faqts : Computers : Programming : Languages : Asp : ASP/VBScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

1 of 7 people (14%) answered Yes
Recently 1 of 7 people (14%) answered Yes

Entry

How to store and compare Passwords as Case Sensitive stored in database (e.g Access).

Nov 22nd, 2006 21:29
Christopher Gardiner, M_ Shahzad,


This is the MS Access Method in IIS using ASP 3. Call this page 
default.asp (referenced in the action of the form.
Notice that the datebase is located at 
http://www.yoursitenamehere.com/fpdb/Users.mdb with a table called 
Users containing columns with the appropriate values found in each 
element below, denoted by RSOrders.fields("InsertColumnNameHere").
Save this file as default.asp
It will provide your input form, validate the Nickname and Password 
against the database and, check that the Password and Re-Enter 
Password match.
It's up to you to make the database and to make sure that the line-
breaks inserted by this site are removed from the code.
There's a lot to take-in here so good luck.
<%
	Dim Conn
	Dim RSOrders
	Dim SQL
	Dim fName
	Dim lName
	Dim nick
	Dim eMail
	Dim password
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
	fName = Request("Fname")
	lName = Request("Lname")
	nick = Request("Nickname")
	eMail = Request("Email")
	password = Request("Password")
'check that the password fields match
	If Request("Password") = Request("ReEnterPassword") Then
'if so, open a connection to the database and table
		Set Conn = Server.CreateObject("ADODB.Connection")
		Set RSOrders = Server.CreateObject("ADODB.Recordset")
		SQL = "Select * from Users;"
		Conn.Open "DBQ=" & Server.MapPath("/fpdb/Users.mdb") 
&";Driver={Microsoft Access Driver (*.mdb)};DriverId=25"
		RSOrders.Open SQL, Conn, 1,2
'loop through the data, checking that the nickname isn't
'taken in either upper or lower case
		Do While Not RSOrders.EOF		
			if LCase(RSOrders.fields("Nickname")) = LCase
(nick) Then
				errMessage="The Nickname already 
exists."
'set the nickname to nothing
'so that it is not re-displayed below
				nick = ""
			end if
			RSOrders.MoveNext
		Loop
'go back to the first item in your database
		RSOrders.MoveFirst
'loop through the data, checking that the email address
'isn't taken in either upper or lower case
		Do While Not RSOrders.EOF		
			if LCase(RSOrders.fields("Email")) = LCase
(eMail) Then
				errMessage= errMessage & " The Email 
already exists."
'set the email address to nothing so that
'it is not re-displayed below
				eMail = ""
			end if
			RSOrders.MoveNext
		Loop
		RSOrders.MoveFirst
		RSOrders.close
	Else
		errMessage="The password fields did not match."
	End If
'If no errors were produced
	If errMessage = "" then
'connect to the database and table
		Set Conn = Server.CreateObject("ADODB.Connection")
		Set RSOrders = Server.CreateObject("ADODB.Recordset")
		SQL = "Select * from Users where 1=2;"
		Conn.Open "DBQ=" & Server.MapPath("/fpdb/Users.mdb") 
&";Driver={Microsoft Access Driver (*.mdb)};DriverId=25"
		RSOrders.Open SQL, Conn, 1,2
'add the submitted information
		RSOrders.AddNew	
		RSOrders("Fname") = fName
		RSOrders("Lname") = lName
		RSOrders("Nickname") = nick
		RSOrders("Email") = eMail
		RSOrders("Password") = password
		RSOrders("Date") = Date()
		RSOrders.Update
		RSOrders.close
                Response.Redirect("congratulations.asp")
	End If
End If
'if the page was not redirected, insert any error messages
'and
'insert the information submitted earlier for re-use.
%>
<html>
<body>
<form method="POST" action="default.asp">
<%=errMessage%><br>
<input type="text" name="Fname" value="<%=fName%>">
<input type="text" name="Lname" value="<%=lName%>">
<input type="text" name="Nickname" value="<%=nick%>
<input type="text" name="Email" value="<%=eMail%>">
<input type="password">
<input type="password" name="ReEnterPassword">
<input type="image" src="yourbuttonimage.gif" value="Submit" 
name="Submit">
</form>
</body>
</html>



© 1999-2004 Synop Pty Ltd