p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

proasp_codeclinic thread: Having problem with login submission page...pleas help!!!!!


Message #1 by "Syed Islam" <moin_ny@y...> on Sat, 1 Dec 2001 03:25:09
I think the better way would just to be attempt to create a recordset with
the one record that matches the criteria, and see if it is .BOF rather than
loop through the entire recordset checking each entry:

strSQL = _
    "SELECT UserID " & _
    "FROM Users " & _
    "WHERE UserName = '" & Replace(Request.Form("UserName"), "'", "''") & "'
" & _
    "AND Password = '" & Replace(Request.Form("Password"), "'", "''")  & "'"

objRS.Open strSQL, objConn

If objRS.EOF then
    ' no matching combination
    ' Access denied
Else
    ' valid combo
End If

Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----- Original Message -----
From: "Steven Broos" <Steven.Broos@n...>
To: "Code Clinic" <proasp_codeclinic@p...>
Sent: Saturday, December 01, 2001 7:37 PM
Subject: [proasp_codeclinic] Re: Having problem with login submission
page...pleas help!!!!!


: You are just checking with only the first record.
: You need a loop like this, that reads the whole recordset:
:
: while not oRS.EOF
: PickUserName = oRS("UserName")
: PickPassword = oRS("Password")
: If EnterUserName = PickUserName AND EnterPassword = PickPassword Then
: response.redirect "http://www25.brinkster.com/moin6/bdchat/op_entry.asp"
: end if
: wend
: response.write "No access"
:
: Success,
: Steven
:
:
: On Saturday 01 December 2001 04:25, you wrote:
: > Hi there,
: > I am creating a page for users. I want my users to login with a User
name
: > and Password. If user name exist in an access database, then go to a
: > specific page. If user name doesn't exist, then go to another page. I
have
: > written ASP code below to perform this function and it works partially.
: > The problem is my code works only for the first record in the table but
: > not for rest of the records. In addition, I have more than 20 records in
: > that table. What I'm doing wrong here? Any help would be greatly
: > appreciated. Thank you.
: >
: > Here is the ASP code for login_submit.asp page:
: >
: >
: > <html>
: >
: > <head>
: > <title>Log in Submit </title>
: > </head>
: >
: > <body bgcolor="#333366" text="#800000" style="font-family: Arial">
: >
: >
: > <%
: >
: > Dim oRS
: > Dim oConn
: > Set oRS=Server.CreateObject("ADODB.Recordset")
: > Set oConn=server.createobject("ADODB.connection")
: > oConn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" &
Server.MapPath
: > ("\moin6\db\BDChat.mdb"),adOpenKeyset,adLockOptimistic
: > oRS.open "Select * from Admins", oConn
: >
: > 'Variables
: > EnterUserName = request.form("txtUserName")
: > EnterPassword = request.form("txtPassword")
: >
: >
: > ssql = "SELECT UserName, Password "
: > ssql = ssql & "FROM Admins "
: > ssql = ssql & "WHERE "
: > ssql = ssql & "UserName = '" & EnterUserName & "' "
: > ssql = ssql & "AND Password = '" & EnterPassword & "'"
: > Response.Write "<BR><BR>" & ssql & "<BR><BR>"
: > set rstemp = oConn.Execute(ssql)
: >
: > If not oRS.EOF Then
: > PickUserName = oRS("UserName")
: > PickPassword = oRS("Password")
: > End If
: >
: >
: >
: > If Not((EnterUserName = PickUserName) AND (EnterPassword 
: > PickPassword)) Then
: > Response.Write "<h3 align=center><font
: > color=#FFFFFF>Your user name or password is invalid</font></h3>"
: > %>
: > <meta HTTP-EQUIV="refresh" content="2;
: > URL=http://www25.brinkster.com/moin6/bdchat/login.asp">
: > <%
: >
: > Else
: >
: > Response.Redirect "http://www25.brinkster.com/moin6/bdchat/op_entry
: > .asp"
: > End if
: >
: > oRS.Close
: > oConn.Close
: >
: > Set oRS = Nothing
: > Set oConn = Nothing
: > %>
: >
: > </body>
: > </html>
: >
: > PS: I tried putting "Do While Not.oRS" loop instead of "If not oRS.EOF
: > Then" but it doesn't perform the function to perform.



  Return to Index