Home arrow ASP arrow Page 4 - Hey... I Remember You!
ASP

Hey... I Remember You!


In my opinion, one of the most annoying things about some websites is logging in. Today, Mitchell will demonstrate how to create a nifty little feature that will allow your site to "remember" its visitors.

Author Info:
By: Mitchell Harper
Rating: 5 stars5 stars5 stars5 stars5 stars / 45
November 15, 2001
TABLE OF CONTENTS:
  1. · Hey... I Remember You!
  2. · Storing the users login details
  3. · Adding new users
  4. · Creating the login page
  5. · The CheckLogin routine
  6. · The "remember me" part
  7. · Conclusion

print this article
SEARCH DEVARTICLES

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.




blog comments powered by Disqus
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...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials