Login through database

Thread Solved

Join Date: Feb 2008
Posts: 85
Reputation: johnny.g is an unknown quantity at this point 
Solved Threads: 3
johnny.g johnny.g is offline Offline
Junior Poster in Training

Login through database

 
0
  #1
Feb 18th, 2008
hiii,,i m a new member of daniweb and new to programming also..
well i have a simple login page in my website,,
currently i am using standard username and password,,,but i would like to have the username and password checked from a table in the database,,
i am using asp.net 2.0 and sql server 2000....
can any1 help me out how to do it exactly????
thnks in advance....
common guys n gals out thr,,,i really need ur help..help me out
Last edited by johnny.g; Feb 18th, 2008 at 5:48 am.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,821
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 117
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso

Re: Login through database

 
0
  #2
Feb 18th, 2008
Create a table to store login and encrypted salt in database, when someone enters a password, use standard encryption algo and see whether the string matches with what is there in database. It is pretty straight forward.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 30
Reputation: dilipv is an unknown quantity at this point 
Solved Threads: 4
dilipv dilipv is offline Offline
Light Poster

Re: Login through database

 
0
  #3
Feb 18th, 2008
hi johnny.g,
There are several article's were available , make Googled and you can definately got some solution on it.
I found out two article based on it. Just visit the link.

http://www.daniweb.com/forums/thread6028.html

http://support.microsoft.com/default...;EN-US;q301240

Hope this will help you.
Thanks & Regards
Dilipv
Dilip Kumar Vishwakarma
Programmer
.Net Consulting
If this post is answer for your query then don't forget to mark as an answer.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 85
Reputation: johnny.g is an unknown quantity at this point 
Solved Threads: 3
johnny.g johnny.g is offline Offline
Junior Poster in Training

Re: Login through database

 
0
  #4
Feb 18th, 2008
Originally Posted by ithelp View Post
Create a table to store login and encrypted salt in database, when someone enters a password, use standard encryption algo and see whether the string matches with what is there in database. It is pretty straight forward.
___________
well my dear,,thnks for ur help,,
i m lookin for a solution,,i have created a table for username and password,
i have also created the sql connection for the same,,
what i want is the code to check the username and password from the table...
hope u understand what i need,,,thnks in advance
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 85
Reputation: johnny.g is an unknown quantity at this point 
Solved Threads: 3
johnny.g johnny.g is offline Offline
Junior Poster in Training

Re: Login through database

 
0
  #5
Feb 18th, 2008
Originally Posted by dilipv View Post
hi johnny.g,
There are several article's were available , make Googled and you can definately got some solution on it.
I found out two article based on it. Just visit the link.

http://www.daniweb.com/forums/thread6028.html

http://support.microsoft.com/default...;EN-US;q301240

Hope this will help you.
Thanks & Regards
Dilipv
_____________________
hey dude,,thnks for the link,,i wil check the link and let u kno,,,thnks 1ce again
c ya
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 174
Reputation: TobbeK is an unknown quantity at this point 
Solved Threads: 3
TobbeK TobbeK is offline Offline
Junior Poster

Re: Login through database

 
0
  #6
Feb 18th, 2008
Here's one simple example where you can receive, check and redirect user logins.
Change the DB table fields and so on to match your own data base.


  1. <%
  2. PW = Request.Form("pass") ' password from the loginform
  3. UN = Request.Form("user") ' username from the loginform
  4.  
  5. SQL = "SELECT * FROM <user_table> WHERE username = '"& UN &"' AND passwd ='"& PW &"'"
  6. Set RS = Conn.Execute(SQL)
  7.  
  8.  
  9. If Not RS.EOF Then ' If the username and password exists in the database
  10.  
  11. Session("valid") = True ' Keep the valid value in session for later use
  12. Session("uid") = RS("<userid>") ' Keep the member userid in session for later use
  13.  
  14. Response.Redirect"some_valid_members_page.asp?uid=" & Session("uid")
  15.  
  16. Else 'If the username and password NOT exists in the database, send them back to your loginpage
  17.  
  18. Response.Redirect"some_page_where_you_have_the_login_form.asp
  19.  
  20. RS.Close
  21. Conn.Close
  22. Set RS = Nothing
  23. Set Conn = Nothing
  24. End If
  25. %>
  26.  
Last edited by TobbeK; Feb 18th, 2008 at 10:30 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Login through database

 
0
  #7
Feb 18th, 2008
That's pretty much it. The only thing you have to worry about is case sensitivity. This depends on your server settings on which it is set to case-sensitive or case-insensitive. You should pull the password from the database and then check it thoroughly. You don't want someone to use "PassWoRd" and allow them to login with "password", you know what I mean?

Just create a connection and recordset. Then create an SQL query to retrieve the password. Check to see if there are any results (EOF = end of file), then compare the two if there are. If there are not any results, post an error to the user. An example of this was above, and is below:
Dim rs, conn, sql, passwd, uname

passwd = Trim(Request.Form("password"))
uname = Trim(Request.Form("username"))

Set conn = Server.CreateObject("ADODB.Connection")
conn.Provider = "this is your connection string. Look one up at http://connectionstrings.com"

Set rs = Server.CreateObject("ADODB.Recordset")

'Select the password from the database where the supplied username exists.
sql = "SELECT userpassword FROM users WHERE username='" & uname & "'"

'Open the connection called "conn"
conn.Open()

'Open a recordset that retrieves the query with connection "conn"
rs.Open sql, conn

if Not rs.EOF then
  'If you haven't reached the end of the recordset, there must be a record!
  if StrComp(rs("userpassword"), passwd, 0) = 0 then
    'The 0 stands for case-sensitive. 1 is case-insensitive.
    'If this command equals zero, then it passed validation.
    'Give them a session to store that they logged in. This way you can check
    'at a later time if they logged in.
    Session("logged") = "True"
    'Send the user to the good pages!
    response.redirect("loggedin.asp")
  else
    'Failed to login, incorrect password.
    'Try not to let them know if they have the right username.
    'Just tell them it all failed.
    response.write("incorrect username or password.")
  end if
else
  'No records, meaning there are no users with that username.
  response.write("incorrect username or password.")
end if

rs.Close()
set rs = nothing

conn.Close()
set conn = nothing
'If you do not close the connection, they will continuously rack up, which will slow down, if not halt your program/website. Always close. Disposing of the variable (setting it to nothing) frees up space for the next user. Not required, but definitely good techniques.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 174
Reputation: TobbeK is an unknown quantity at this point 
Solved Threads: 3
TobbeK TobbeK is offline Offline
Junior Poster

Re: Login through database

 
0
  #8
Feb 18th, 2008
.... when user finally is logged in to the good page, you can put a code like this at top of that page.

When session dies, which it does after a while if the user is inactiv or by closing down the browser. The session lifetime can also be set. However if the user "session" is no longer valid then user cannot view the page. That is why you keep this session value in the first place.

If Session("valid") <> True Then
Response.Redirect"some_page_where_you_have_the_login_form.asp"
End If


Just for fun - check your session settings

<html>
<body>

<p>
The timeout for this session is
<%
Response.Write(Session.Timeout)
%>
minutes.
</p>

</body>
</html>
Last edited by TobbeK; Feb 18th, 2008 at 2:33 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 85
Reputation: johnny.g is an unknown quantity at this point 
Solved Threads: 3
johnny.g johnny.g is offline Offline
Junior Poster in Training

Re: Login through database

 
0
  #9
Feb 19th, 2008
Originally Posted by TobbeK View Post
.... when user finally is logged in to the good page, you can put a code like this at top of that page.

When session dies, which it does after a while if the user is inactiv or by closing down the browser. The session lifetime can also be set. However if the user "session" is no longer valid then user cannot view the page. That is why you keep this session value in the first place.

If Session("valid") <> True Then
Response.Redirect"some_page_where_you_have_the_login_form.asp"
End If


Just for fun - check your session settings

<html>
<body>

<p>
The timeout for this session is
<%
Response.Write(Session.Timeout)
%>
minutes.
</p>

</body>
</html>
_____________________________
thnks,, i m going thr the code given by u,,will let u kno soon
for the session part,,,i hav given time out in the web.config file using authentication and authorization,,is tht ok??,,thnks
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Login through database

 
0
  #10
Feb 19th, 2008
That's not asp, isn't that asp.net? different language, completely.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC