ASP
  Home arrow ASP arrow Page 3 - Creating a members area with ASP
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  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 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

Creating a members area with ASP
By: James Crowley
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    2002-04-25

    Table of Contents:
  • Creating a members area with ASP
  • Creating the database
  • The register.asp code
  • The login.asp code
  • The members area
  • 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


    Creating a members area with ASP - The register.asp code


    (Page 3 of 6 )

    <%
    Option Explicit
    Dim strError, strSQL
    'see if the form has been submitted
    If Request.Form("action")="register" Then
       'the form has been submitted
       '// validate the form
       'check if a username has been entered
       If Request.Form("username") = "" Then _
           strError = strError & "- Please enter a username<br>" & vbNewLine
       'check if a password has been entered
       If Request.Form("password") = "" Then _
           strError = strError & "- Please enter a password<br>" & vbNewLine
       'check if the passwords are the same... but don't display it if the password field is blank.
       If Request.Form("password") <> Request.Form("password_confirm") _
           And Request.Form("password") <> "" Then _
               strError = strError & "- Your passwords do not match<br>" & vbNewLine
       '// check if an error has occured
       If strError = "" Then
          'continue
          'include database connection code
          %>
          <!--#include file="inc-dbconnection.asp"-->
          <%
          On Error Resume Next
          '// create the SQL
          strSQL = "INSERT INTO members ([username],[password]) VALUES " & _
             "('" & fixQuotes(Request.Form("username")) & "','" & _
             fixQuotes(Request.Form("password")) & "')"
          '// run the SQL
          objConn.Execute strSQL
          '// check for an error
          '// ATTENTION: this should be changed depending on the database provider
          If Err.Number = -2147467259 Then
              strError = "- That username is already in use. Please choose another<br>" & vbNewLine
          ElseIf Err.Number <> 0 Then
              strError = "- An error occured. " & Err.Number & " : " & _
                  Err.Description & "<br>" & vbNewLine
          Else
              'record created... redirect
              Response.Redirect "login.asp?msg=" & Server.URLEncode("Thank you for registering")
              Response.End
          End If
          'restore standard error handling
          On Error Goto 0
       End If
       If strError <> "" Then
          'output the error message
          'add extra HTML...
          strError = "<p><font color=""#FF0000"">The following errors occured:" & _
             "</font><br>" & vbNewLine & strError
       End If
    End If
    Function fixQuotes(strData)
      fixQuotes = Replace(strData,"'","''")
    End Function
    %>
    <html>
    <head>
    <title>My Website's Registration Page</title>
    </head>
    <body>
    <h1>Member Registration</h1>
    <p>Please fill out the following form to register as a member, and
     gain access to our members area.</p>
    <%=strError%>
    <form action="register.asp" method="POST">
    <input type="hidden" name="action" value="register">
    <table border="0">
    <tr>
      <td><b>Username</b></td>
      <td><input type="text" maxlength=20 name="username"
     value="<%=Server.HTMLEncode(Request.Form("username"))%>"></td>
    </tr>
    <tr>
      <td><b>Password</b></td>
      <td><input type="password" maxlength=20 name="password"
     value="<%=Server.HTMLEncode(Request.Form("password"))%>"></td>
    </tr>
    <tr>
      <td><b>Password Confirm</b></td>
      <td><input type="password" maxlength=20 name="password_confirm"
     value="<%=Server.HTMLEncode(Request.Form("password_confirm"))%>"></td>
    </tr>
    <tr>
      <td> </td>
      <td><input type="submit" value="Complete Registration"></td>
    </tr>
    </table>
    </form>
    </body>
    </html>

    A large proportion of this code is almost identical to that of register.asp. The code first checks to see if the form has been submitted. If it has, it uses the same validation technique as before to see if a username and password has been specified. If it hasn't, an error message is displayed. If it has, then it checks the username/password combination by querying the database for that username.

    If objRS.EOF Then the username hasn't been found; display error message. Otherwise, we check the password returned from the database, and compare it to the one the user has just entered. Once again, if they are incorrect, we tell the user that.

    If the username/password combination is correct, we set the loggedin value of our session data to 1, and also save the user id. These session data variables are available outside login.asp, so our member’s pages can check if we are logged in or not. Therefore, once setting this data, we simply redirect to default.asp ; the members home page (we are assuming that you have a separate /members/ directory).

    More ASP Articles
    More By James Crowley


     

    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-2010 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek