Wife/Girlfriend/Sister?
Pepper Spray &
Stun Gun Specials!
KEEP THEM SAFE.
 CoverYourASP --> Adding member services --> Part 3

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
51 active users
4050 visitors today
6812 pages today
how is this done?
Tools I use

CoverYourASP
Copyright © 1999-2010 James Shaw.
All rights reserved.

ASP.NET Blog
RSS submissions
E-commerce

Now open source with SourceForge!

Signing in and out
The sign in process starts with a call to ShowLoginStatus( ) in utils/Header.asp. The ShowLoginStatus function contains the following code:

if ( IsLoggedIn ( ) )
   Out ( '<a href="MemberLogout.asp">Sign out</a> ' + sMemberName );
else
   Out ( 'Join in the fun! <a href="MemberLogin.asp">Sign in</a>' );

This will be the first call to IsLoggedIn( ), which first checks if the function has already been called on this page (if bLoggedIn is undefined), then checks if the Session has been signed in.

Every visitor gets assigned a unique session - Session variables like this are available to every page on your web site, and allow you to store data that is unique to each visitor.

If signed in then some other global variables are assigned from the current Session - this just makes it less expensive to access this data later in the page.

if ( bLoggedIn == undefined )
{
    bLoggedIn = Session ( 'Authenticated' );

   if ( bLoggedIn )
   {
      sMemberName = Session ( 'MemberName' );
      sMemberEmail = Session ( 'MemberEmail' );
      nMemberID = Session ( 'MemberID' );
      nMemberLevel = Session ( 'MemberLevel' );
   }
}

return bLoggedIn;

Back in ShowLoginStatus( ), the user is either shown an option to sign in, or sign out. Signing in is done with a simple form asking for the member email and password. The ValidateLogin( ) function is then called when the form is submitted. Let's look at the ValidateLogin( ) function:

// connect to database
DBInitConnection ( );

// search for matching email/password
DBGetRecords ( 'SELECT MemberID,Name,MemberLevel FROM Members WHERE Confirmed=True AND Email=\'' + sEmail + '\' AND MemberPassword=\'' + sPassword + '\'' );

if ( !oRecordSet.EOF )
{
   Session ( 'MemberEmail' ) = sEmail;
   Session ( 'MemberID' ) = oRecordSet ( 0 ) - 0;
   Session ( 'MemberName' ) = '' + oRecordSet ( 1 );
   Session ( 'MemberLevel' ) = oRecordSet ( 2 ) - 0;
   Session ( 'Authenticated' ) = 1;
}

// release database
DBReleaseConnection ( );

So the database is searched for a matching email/password. If found the Session variables are initialized to the correct values, and the visitor is "signed in"!

Signing a member out is a little easier! A call to Logout( ) in utils/Login.asp contains this code:

// clear the authenticated status
Session ( 'Authenticated' ) = 0;

Big Important Note: Before I leave the subject of signing in, you should be aware that my implementation is NOT SECURE. Password information over a normal HTTP connection can be seen by anyone. On my site this isn't important, but remember to send important information via HTTPS in real life.

Part 4: Signing in automatically with a cookie...

Featured sponsor
My favorite resources

Tiki Statues - Tiki Masks - Tiki Totems



New Proposal Kit Professional 5.1
Brand yourself as a top professional: create quotes and amazing proposals and get many legal documents free!

The latter saved me 3 times the purchase price on the first day I owned it!


See my source code
wherever you see this icon...

You can also download the entire site source code for FREE!


I share my content

Supporting ASPRSS

Do you need a quick and easy way to link to my articles? All the information you need is published with ASPRSS...