SunQuest
 
       ASP
  Home arrow ASP arrow Page 4 - Hey... I Remember You!
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM developerWorks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

Hey... I Remember You!
By: Mitchell Harper
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2001-11-15

    Table of Contents:
  • Hey... I Remember You!
  • Storing the users login details
  • Adding new users
  • Creating the login page
  • The CheckLogin routine
  • The "remember me" part
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Hey... I Remember You! - Creating the login page


    (Page 4 of 7 )

    Before we can remember users credentials, they must login and choose for us to remember them. Never keep a users details without their consent: you'll loose their business for life and they wont come back to your site.

    Create a new ASP script and call it login.asp. Add the following code to the page:

    1. <html>

    2. <head>

    3. <title> Login </title>

    4. </head>

    5.

    6. <body bgcolor="#ffffff">

    7. <form action="login.asp" method="post">

    8. <input type="hidden" name="what" value="checklogin">

    9. <h1>Please Login Below</h1>

    10. <pre>

    11. Username: <input type="text" name="uname" maxlength="20">

    12. Password: <input type="password" name="pass" maxlength="20">

    13. <input type="checkbox" value="ON"> Remember Me

    14. <br><br><input type="submit" value="Login Now">

    15. </pre>

    16. </form>

    17. </body>

    18. </html>


    This page is nearly exactly the same as our adduser.asp form, accept we've changed the action attribute of the form to “login.asp” and the value of the what variable to “checklogin”. We've also added a checkbox. If you're wondering, yes, we will be sending the form post to the same page that generated it (login.asp).

    Modify the code that we just created for the login.asp page above so that it looks like this:

    1. <%

    2.

    3. dim strWhat

    4. strWhat = Request.Form("what")

    5.

    6. select case strWhat

    7. case "checklogin"

    8. CheckLogin()

    9. case else

    10. ShowLoginForm()

    11. end select

    12.

    13. sub ShowLoginForm()

    14.

    15. %>

    [HTML code goes here]

    34. <%

    35. end sub

    36.

    37. sub CheckLogin()

    38.

    39. dim objConn

    40. dim objRS

    41. dim strUserName

    42. dim strPassword

    43. dim strRememberUser

    44.

    45. strUserName = Request.Form("uname")

    46. strPassword = Request.Form("pass")

    47. strRememberUser = Request.Form("remember")

    48.

    49. set objConn = Server.CreateObject("ADODB.Connection")

    50. set objRS = Server.CreateObject("ADODB.Recordset")

    51.

    52. objConn.Open "Provider=SQLOLEDB; Data Source=(local); Initial Catalog=smartlogin; UId=sa; Pwd="



    52. objRS.ActiveConnection = objConn

    53. objRS.LockType = adLockReadOnly

    54. objRS.CursorType = adUseForwardOnly

    55. objRS.Open "select count(*) from logins where user_name = '" & strUserName & "' and password = '" & strPassWord & "'"



    56. if objRS.Fields(0).Value > 0 then

    57. if strRememberUser = "ON" then

    58. Response.Cookies("u") = strUserName

    59. Response.Cookies("p") = strPassword

    60. Response.Cookies(“u”).Expires = Date()+30

    61. Response.Cookies(“p”).Expires = Date()+30

    else

    62. Response.Cookies(“u”).Expires = Date()-1

    63. Response.Cookies(“p”).Expires = Date()-1

    64. end if

    65. Response.Write "Hello " & strUserName & ". You have logged in successfully."

    66. else

    67. Response.Write "User " & strUserName & " doesn't exist in the logins database."

    68. end if

    69.

    70. end sub

    71. %>


    The layout of our login.asp page is similar to the adduser.asp page. We are checking the value of the Request.Form(“what”) variable and either displaying the form or checking the login credentials posted from the form.

    Everyone should be OK with the ShowLoginForm sub routine, so we will talk about the sub routine that will allow our ASP page to check the login details and remember the user if they've chosen it: the CheckLogin routine.



    More ASP Articles
    More By Mitchell Harper


     

    ASP ARTICLES

    - Central Scoreboard with Flash and ASP
    - Calorie Counter Using WAP and ASP
    - Creating PGP-Encrypted E-Mails Using ASP
    - Be My Guest in ASP
    - Session Replacement in ASP
    - Securing ASP Data Access Credentials Using t...
    - The Not So Ordinary Address Book
    - Adding and Displaying Data Easily via ASP an...
    - Sending Email From a Form in ASP
    - Adding Member Services in ASP
    - Removing Unconfirmed Members
    - Trapping HTTP 500.100 - Internal Server Error
    - So Many Rows, So Little Time! - Case Study
    - XDO: An XML Engine Class for Classic ASP
    - Credit Card Fraud Prevention Using ASP and C...







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway