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

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
  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

Hey... I Remember You! - The CheckLogin routine
(Page 5 of 7 )

The CheckLogin routine is the core of our ASP application and will handle the validation of the user credentials as well as the code that will help our ASP scripts remember the current user.

Starting on line 45, we are getting the values of the username and password that the user has submitted via the form. On line 46, the strRemember variable will be set to “ON” if the “Remember Me” checkbox was checked on the login form.

Lines 52 to 54 open a connection to our database server and declare a new recordset object. The LockType and CursorType of the recordset object are set to adLockReadOnly and adUseForwardOnly respectively. These are imported in line 1 via the use of a meta tag. This special meta tag extracts all of the variables from the MSADO15.dll file and lets our ASP script use them as if we had manually declared them ourselves.

Because we have set both LockType and CursorType values for our recordset, it will only be able to fetch records in a forward seeking motion. This greatly reduces the time it takes to fetch records from the database, because SQL doesn't have to create any locks or temporary data for modified or new records.

Line 55 executes a SELECT command to get a count of the number of users whose credentials match those passed from our login form and stores the result in our recordset object.

On line 56, we check how many users the SQL COUNT() function returned. Because we used a “select count(*)” query, our recordset will contain just one row with one field containing the number of users that matched the credentials we supplied.

On line 57, if at least one user was found matching the credentials from the login form, we check whether or not they have chosen to be remembered. If they have, (strRememberUser = “ON”) then we set two cookie values containing the username and password values (u and p). If they haven't, we wont set the cookie values, but we will set their expiry date to yesterday, which will remove them from the users machine if they existed previously. Alternatively, lines 60 and 61 set the expiry date of our username and password cookies to 30 days from now if the user has chosen to be remembered.

Lastly, if the login was successful, our script will write one line to the browser: “Hello John. You have logged in successfully”. On the other hand, if the login fails, our ASP script will tell the user that their credentials weren't found in the database.
blog comments powered by Disqus

- 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 

Developer Shed Affiliates


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