Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

login with asp.net and vb.net and sql database help

Status
Not open for further replies.

Shift838

IS-IT--Management
Joined
Jan 27, 2003
Messages
987
Location
US
I have a login page, pretty standard, user ID and password. I have my code query the database for a role of '1' (admin role) I know I am putting the id and password in right, but it will not log me in, still returning a false for matching. any clues? my code is below:

strsql = "Select * FROM reg_user"
Dim con As New OleDb.OleDbConnection("Provider=SQLOLEDB; Data Source=localhost; Initial Catalog=webx; User ID=webuser; Password=password")
Dim cmd As New OleDb.OleDbCommand(strsql, con)
Dim reader As OleDb.OleDbDataReader
Dim fullname, cphone As String
If Len(txtuserid.Text) > 4 Or Len(txtpword.Text) > 6 Then

Try
' Open connection to sql database
con.Open()
reader = cmd.ExecuteReader
' Loop through database


While (reader.Read)

If reader("u_name") = struser And reader("u_password") = strpword Then
bvalue = True
fname = reader("u_firstname")
lname = reader("u_Lastname")
cname = reader("u_company")
cemail = reader("u_email")
csubdomain = reader("u_subdomain")
cphone = reader("u_phone")


txtfullname.Text = fname & " " & lname
txtphone.Text = cphone
txtcompany.Text = cname

Else
bvalue = False

End If

End While
' close connection to sql database
'reader.Close()

'displays error message
Catch err As Exception
lblstatus.Text = err.Message

Finally

If (Not con Is Nothing) Then
con.Close()
End If

End Try

If bvalue = True Then

lblstatus.Text = "Logged On!"
Server.Transfer("eventsreg.aspx")

Else

lblstatus.Text = "Check Username and password! If you are not a registered user please register."

End If
Else
lblstatus.Text = "UserID must be atleast 4 characters and passwords must be atleast 6 characters in length."
End If
 
It would be better if you just queried the database for the one user and get back the one password if the user existed.
Select * FROM reg_user where u_name='" & struser & "'"

Useing your method, you need to exit the while loop once you find the correct user.
If reader("u_name") = struser And reader("u_password") = strpword Then

..Do.....stuff

Exit While
End While


 
RTomes is exactly right. You should only be returning one record to see if you can log in successfully. Taking what RTomes said above, you would then simply check within the reader to see if they logged in correctly. e.g.
Code:
Dim bolFound as Boolean = False
...
While myReader.Read
	bolFound = True
End While

If bolFound = True Then
	' Correct login
Else
	' Incorrect login
End If


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
But this does not verify the password. I need it to verify the password before logging the user in. It only checks that they can login and then redirects them.

 
I have figured this one out, thanks to Rtomes and Ca8msm! Thanks guys, you put me on the right track..
 
You return the one record as shown above and compare the passwords.

Are your user ids case sensative also? If so then...

If Mike is logging in then use the sql query that gets back all users named Mike.

Then iterate thru them with the reader comparing user name and password. Comparing text in .Net is case sensative. "Mike" does not equal "mike".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top