Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old September 4th, 2006, 08:53 AM
degsy degsy is offline
Contributing User
ASP Free God 2nd Plane (6000 - 6499 posts)
 
Join Date: Aug 2005
Location: North East, UK
Posts: 6,191 degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 19 h 41 m 52 sec
Reputation Power: 121
Registration / Signup script

This is a Registraction script for ASP VBScript & Access with basic validation

It can be used in conjunction with Basic Membership / Login system

asp Code:
Original - asp Code
  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
  2. <%
  3. 'Code to prevent the page from being cached
  4. Response.CacheControl = "no-cache"
  5. Response.AddHeader "Pragma", "no-cache"
  6. Response.Expires = -1
  7.  
  8. 'Some site constants
  9. site_url = "http://" & Request.ServerVariables("SERVER_NAME") & "/"
  10. site_name = "mySite.com"
  11. admin_name = "Admin"
  12. admin_email = "myEmail@mySite.com"
  13. sendEmail = True
  14.  
  15. 'Check if the form has been submitted
  16. If Request.Form("Submit") = "Register" Then
  17.    
  18.     'Simple string validation function. This can be expanded on.
  19.     Function validateStr(str)
  20.         temp = str
  21.         temp = Trim(temp)
  22.         temp = Replace(temp,"'","''")
  23.        
  24.         validateStr = temp
  25.     End Function
  26.    
  27.     'Simple email validation function. e.g. abc123@domain.ext
  28.     Function validateEmail(email)
  29.         isValidE = True
  30.         set regEx = New RegExp
  31.        
  32.         regEx.IgnoreCase = False
  33.        
  34.         regEx.Pattern = "^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
  35.         isValidE = regEx.Test(email)
  36.        
  37.         validateEmail = isValidE
  38.     End Function
  39.    
  40.     'Grab the form data
  41.     user_name = validateStr(Request.Form("user_name"))
  42.     user_pass = validateStr(Request.Form("user_pass"))
  43.     confirm_pass = validateStr(Request.Form("confirm_pass"))
  44.     user_email = validateStr(Request.Form("user_email"))
  45.    
  46.     'Data validation
  47.     If user_name = "" Then
  48.         errMsg = "-Please enter a username<br />"
  49.     End If
  50.    
  51.     If user_pass = "" Then
  52.         errMsg = errMsg & "-Please enter a password<br />"
  53.     ElseIf user_pass <> confirm_pass Then
  54.         errMsg = errMsg & "-Passwords do not match<br />"
  55.     End If
  56.    
  57.     If user_email = "" Then
  58.         errMsg = errMsg & "-Please enter an email address<br />"
  59.     ElseIf validateEmail(user_email) = False Then
  60.         errMsg = errMsg & "-Email addrress is not valid<br />"
  61.     End If
  62.    
  63.     'If there are no errors then continue with the registration
  64.     If Len(errMsg) = 0 Then 
  65.         Set conn=Server.CreateObject("ADODB.Connection")
  66.         conn.Provider="Microsoft.Jet.OLEDB.4.0"
  67.         conn.Open Server.MapPath("login.mdb")
  68.         Set rsCheckUser = Server.CreateObject("ADODB.recordset")
  69.        
  70.         'Select the data from the database using the submitted data.
  71.         rsCheckUser.Open "SELECT user_id FROM users WHERE user_name = '" & user_name & "' Or user_email = '" & user_email & "'", conn
  72.            
  73.             'Check if a match was found.
  74.             If NOT rsCheckUser.EOF Then
  75.                 'If a match was found output an error message.
  76.                 errMsg = "-Details already exist"
  77.             Else
  78.                 'Insert the data into the database
  79.                 sql = "INSERT INTO users (user_name, user_pass, user_email) VALUES " &_
  80.                       "('" & user_name & "'," &_
  81.                       "'" & user_pass & "'," &_
  82.                       "'" & user_email & "')"
  83.                 conn.Execute sql
  84.                 registered = True
  85.                 msg = "Thankyou for registering at " & site_name
  86.                
  87.                 'If sendEmail is true then send the user an email
  88.                 If sendEmail = True Then
  89.                     'Set the body text message for the email
  90.                     body = "Name: " & user_name & vbCRLF &_
  91.                            "Pass: " & user_pass & vbCRLF &_
  92.                            "Email: " & user_email & vbCRLF &_
  93.                            vbCRLF & vbCRLF & msg & vbCRLF & "You can login at " & site_url & "login.asp"
  94.                           
  95.                     Set myMail=CreateObject("CDO.Message")
  96.                         myMail.Subject= msg
  97.                         myMail.From= """" & admin_name & """<" & admin_email & ">"
  98.                         myMail.To= """" & user_name & """<" & user_email & ">"
  99.                         myMail.TextBody=body
  100.                         myMail.Send
  101.                         emailSent = True
  102.                     Set myMail=nothing
  103.                 End If
  104.            
  105.             'Clear form details
  106.             user_name = ""
  107.             user_pass = ""
  108.             user_email = ""
  109.                
  110.             End If
  111.         rsCheckUser.Close
  112.         conn.Close
  113.        
  114.     End If
  115. End If
  116. %>
  117. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  118. <html xmlns="http://www.w3.org/1999/xhtml">
  119. <head>
  120. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  121. <title>Register</title>
  122. <style type="text/css">
  123. <!--
  124. .errmsg {
  125.     font-family: Verdana, Arial, Helvetica, sans-serif;
  126.     font-size: 12px;
  127.     font-weight: bold;
  128.     color: #FF0000;
  129.     background-color: #FFFF99;
  130. }
  131. body,td,th {
  132.     font-family: Arial, Helvetica, sans-serif;
  133.     font-size: 12px;
  134.     color: #0099FF;
  135.     font-weight: bold;
  136. }
  137. body {
  138.     background-color: #F9F9F9;
  139. }
  140. -->
  141. </style>
  142. </head>
  143.  
  144. <body>
  145. <%If Len(errMsg) > 0 Then %>
  146. <span class="errmsg">Error: <br /><%=errMsg%></span>
  147. <%ElseIf Len(msg) > 0 Then %>
  148. <span class="errmsg">Message: <br /><%=msg%>
  149.     <%If emailSent = True Then%>
  150.     An email has been sent to the address that you signed up with<br />
  151.     <%End If%>
  152.     <%If registered = True Then%>
  153.     You can login <a href="<%=site_url%>login.asp">HERE</a><br />
  154.     <%End If%>
  155. </span>
  156. <%End If%>
  157. <form name="form1" id="form1" method="post" action="">
  158.   <table width="300" border="0" cellspacing="0" cellpadding="2">
  159.     <tr>
  160.       <td>Username</td>
  161.       <td><input name="user_name" type="text" id="user_name" value="<%=user_name%>" /></td>
  162.     </tr>
  163.     <tr>
  164.       <td>Password</td>
  165.       <td><input name="user_pass" type="password" id="user_pass" value="<%=user_pass%>" /></td>
  166.     </tr>
  167.     <tr>
  168.       <td>Confirm Password </td>
  169.       <td><input name="confirm_pass" type="password" id="confirm_pass" /></td>
  170.     </tr>
  171.     <tr>
  172.       <td>Email</td>
  173.       <td><input name="user_email" type="text" id="user_email" value="<%=user_email%>" /></td>
  174.     </tr>
  175.     <tr>
  176.       <td>&nbsp;</td>
  177.       <td><input type="submit" name="Submit" value="Register" /></td>
  178.     </tr>
  179.   </table>
  180. </form>
  181. </body>
  182. </html>
Attached Files
File Type: zip register_login.zip (11.8 KB, 888 views)
__________________
CyberTechHelp

Last edited by degsy : September 5th, 2006 at 04:14 AM. Reason: Script updated

Reply With Quote
  #2  
Old September 4th, 2006, 08:55 AM
degsy degsy is offline
Contributing User
ASP Free God 2nd Plane (6000 - 6499 posts)
 
Join Date: Aug 2005
Location: North East, UK
Posts: 6,191 degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 19 h 41 m 52 sec
Reputation Power: 121
Things you can do

You could set up a constants file to hold details such as the site_name, site_url, adminEmail etc.

You could setup a functions file for the validation and email functions.

You could increase the security on the submitted data

e.g.

Code:
<%
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then

Function validPass(pass)
	For x=1 To Len(pass)
		str = Mid(UCase(pass),x,1)
		asci = Asc(str)

		If (asci > 64 And asci < 91) Or IsNumeric(str) Or str = "_" Or str = "-" Then
			validPass = True
		Else
			validPass = False
			Exit Function
		End If
	Next
End Function

	pass = Trim(Replace(Request.Form("pass"),"'","''"))
	
	If ValidPass(pass) = True Then
		Response.Write "valid pass"
	Else
		Response.Write "Error"
	End If
End If
%>
<form name="form1" id="form1" method="post" action="">
  <input name="pass" type="text" id="pass" />
  <input type="submit" name="Submit" value="Submit" />
</form>

Reply With Quote
  #3  
Old January 10th, 2007, 09:36 AM
degsy degsy is offline
Contributing User
ASP Free God 2nd Plane (6000 - 6499 posts)
 
Join Date: Aug 2005
Location: North East, UK
Posts: 6,191 degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 19 h 41 m 52 sec
Reputation Power: 121
Enhanced script with an email verification system

register.asp
asp Code:
Original - asp Code