Login Authentication

J

janet

hI ...

I am newbie to ASP ... i am trying to write a code to
accept login and passwor from a user and verify through a
table created in MySQL.

I am just trying to write a code on my own seeking help
from code here and there and from my understanding. I am
completely zapped :-(((

here is my code:-

DIM SQL
DIM RSA
DIM QUERY1

ConnString = "Driver={MySQL ODBC 3.51 Driver};"
ConnString = ConnString & "Port=3306; "
ConnString = ConnString & "DATABASE=test; "

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ConnString

<FORM ACTION="login.asp" METHOD="post">
<TABLE BORDER=0>
<TR>
<TD ALIGN="right">LOGIN:</TD>
<TD><INPUT TYPE="text"
NAME="txtID"></INPUT></TD>
</TR>
<TR>
<TD ALIGN="right">PASSWORD:</TD>
<TD><INPUT TYPE="password"
NAME="txtPASSWORD"></INPUT></TD>
</TR>
<TR>
<TD ALIGN="right"></TD>
<TD><INPUT TYPE="submit"
VALUE="Login"></INPUT>
<INPUT TYPE="reset"
VALUE="Reset"></INPUT>
</TD>
</TR>
</TABLE>
</FORM>

QUERY1 = "SELECT stUDENT_ID,STUDENT_PASSWORD from
STUDENT_INFO"
SET RSA = = Server.CreateObject("ADODB.Recordset")
Set RSA = conn.Execute(QUERY1,,adCmdText)

if RSA.EOF then
response.Write("NO MATCH")
else
if ([QUERY1.STUDENT_ID] = [txtID]) AND
([QUERY1.STUDENT_PASSWORD] = [txtPASSWORD]) then

response.write "<p>" & "<center>" & "U CAN " & "</center>"
& "</p>"

else
response.write "No ID FOUND"

end if

Set rs = Nothing
Set conn = Nothing
%>


I know my code is not at all written nicely! Can anyone
help me with a sample code for user-id verification? I
want to know how to write a code using ASP (MYSQL). I dont
even know where to put the % sign and whether html comes
before select query...i am all so frustrated and confused !

any sample code help would vbe highly appreciated!

thanks!!!:confused:
 
D

Dan Brussee

hI ...

I am newbie to ASP ... i am trying to write a code to
accept login and passwor from a user and verify through a
table created in MySQL.

I am just trying to write a code on my own seeking help
from code here and there and from my understanding. I am
completely zapped :-(((

here is my code:-

I know my code is not at all written nicely! Can anyone
help me with a sample code for user-id verification? I
want to know how to write a code using ASP (MYSQL). I dont
even know where to put the % sign and whether html comes
before select query...i am all so frustrated and confused !

I snipped your code - better to start fresh.

First off, make sure your connection string is valid. After that, work
on the form where the user will enter the data. Now you can make it
dynamic.

Work on the fundimentals. ASP pages allow server side script to build
the web page. Any server script is enclosed in <% and %> tags, so to
include the text "ASP IS COOL", all you do is put <%="ASP IS COOL"%>
inline where you want it.

When you need to use a database or other server things, just be sure
you get what you need before you need it. Sounds simple and it is. If
you need to test a field in a database, do it before the spot in your
HTML that you need to know if the value is there.

In order to test for a username / password, you will need to have a
form where the user can enter that information. Above that, you will
need a database connection and query to see if the one that may (or
may not) have already been entered is correct. Your example SQL needs
some work Im afraid. Let's say you have 2 inputs in your HTML form
named UN and PW and you simply pass them in the query string (not a
good idea, but I will leave that for you to figure out). In ASP, you
might do something like:

<%
' Make connection to DB however it works for you and set a connection
' object - in my case I shall name it conn.
sSQL = "SELECT Username, Password FROM UserTable WHERE "
sSQL = sSQL & "Username = '" & request.querystring("UN") & "' "
sSQL = sSQL & "AND Password = '" & request.querystring("PW") & "' "

set rs = conn.execute(sSQL)
if rs.eof then
LoginOk = False
else
LoginOk = True
end if

%>

Notice that I segregate the entire set of script code with <% and %>
tags. Now, later in the HTML file, when you want to know what
happened, you can simply test the LoginOk variable like:

<% if LoginOk = False then %>
Try it again using a real username and password!
<% end if %>

This gives you very general information and would need to be expanded
taking into account that you would probably want to redirect to
another page if login is successful, etc.
 
J

janet

hey thanks

for explaining so nicely.... and takign so much time to
write all .. i will now try and figure by what u said.
thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,114
Latest member
GlucoPremiumReview
Top