Question about login script

G

Guest

Hi,

I have a login page. Where user enters an email and password. Then I;m
checking if user account is active or not. Before a user can login, he needs
to activate his account. If the account is active then Active field is set
to yes (1) otherwise to no (0).

If the user’s account is active then I check whether this is user’s first
visit or not. If it is user’s first visit then I redirect user to
‘newuser.asp’ page otherwise to ‘returnuser.asp’.

If the user’s account is not active then I send the user to login page with
‘default.asp?pw=0’

For some reason the SQL statement

strSQL = "SELECT * FROM testusers " & "WHERE E_Mail='" &
Request.Form("txtEmail") & "' AND Password = '" & Request.Form("txtUserPass")
& "' AND Active = 1 ;"

is not working because I can see that the user’s account is active, email
and password all exist in the database but the script keeps directing the
user to loginpage as if the record doesn’t exist.

The SQL query that above statemtn produces is,

SELECT * FROM testusers WHERE E_Mail='(e-mail address removed)' AND Password =
'joegreen' AND Active = 1 ;

I am not able to find the mistake I am making. Can someone help me please.

Thanks,

Joe


<%
'Using a DSN connection.
Dim objConn
Dim objRS

Set objConn = Server.CreateObject("ADODB.Connection")
'objConn.ConnectionString = "DSN=PKMSolutionEval"
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=E:\ databases\test.mdb;"

Set objRS=Server.CreateObject("ADODB.Recordset")
'objRS.Open "testusers", objConn
strSQL = "SELECT * FROM testusers " & "WHERE E_Mail='" &
Request.Form("txtEmail") & "' AND Password = '" & Request.Form("txtUserPass")
& "' AND Active = 1 ;"
objRS.Open strSQL, objConn, adOpenForwardOnly, adLockReadOnly, adCmdText

If Not objRS.EOF And Not objRS.BOF Then

If objRS.Fields("First_Visit") = "True" Then
'first time visitor
strSQL = "UPDATE dndusers SET First_Visit = 0 WHERE E_Mail='" &
Request.Form("txtEmail") & "' AND Password = '" & Request.Form("txtUserPass")
& "';"
Set updateCmd = Server.CreateObject("ADODB.Command")
With updateCmd
.ActiveConnection = objConn
.CommandText = strSQL
.Execute
End With
objRS.Close()

objConn.Close()
Set objConn = Nothing

Response.Redirect("newuser.asp")
Else
'retruning user
objRS.Close()

objConn.Close()
Set objConn = Nothing

Response.Redirect("returnuser.asp")
End If
Else
'user don't exisit
objRS.Close()
objConn.Close()
Set objConn = Nothing

Response.Redirect("default.asp?pw=0")

End If

objConn.Close()
Set objConn = Nothing

%>
 
T

Tom.PesterDELETETHISSS

- Are you sure a record is returned? Check this be printing the objRS.Recordcount
to the page. It should be 1 of course.

- Are you sure that Response.Redirect("default.asp?pw=0") is executed each
time? Maybe the good redirect happens but some other code in another page
does a redirect to 'default.asp?pw=0' and you think this page did that.

I hope it helps...

Cheers,
Tom Pester
 
G

Guest

Yes when I used objRS.RecordCount, I got -1, so I changed the statement from

objRS.Open strSQL, objConn, adOpenForwardOnly, adLockReadOnly,
adCmdText

to

objRS.Open strSQL, objConn, 3, 3, adCmdText

with

strSQL = "SELECT * FROM dndusers " & "WHERE E_Mail='" &
Request.Form("txtEmail") & "' AND Password = '" & Request.Form("txtUserPass")
& "';"

and I got recordcount as 1.

But when I added Active = 1 to SQL statement and run

strSQL = "SELECT * FROM dndusers " & "WHERE E_Mail='" &
Request.Form("txtEmail") & "' AND Password = '" & Request.Form("txtUserPass")
& "' AND Active = 1 ;"

the recordcount is 0

this is why the I keep getting redirected to login page - default.asp?pw=0

Is something wrong with my SQL statement?

I checked the 'Active' which is a Yes/No data field in MS Access DB is
checked that is set to 1, so I should get recordcount as 1 instead of 0.

Can someone help me locate the error. My head is not working anymore.

Thanks,

Joe
 
T

Tom.PesterDELETETHISSS

Hi Joe,

I hope I solved it. Try

AND Active = true

instead of

AND Active = 1

Let me know if you have any more questions..

Cheers,
Tom Pester
 
G

Guest

Hi Joe,

the best thing would be debug the page with response.write and you will get
some clue where its going wrong.

Vijay Pote
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top