Forgot Password Tool ASP Script - ASP Web Pro
  Active Server Pages Programming by ASP Web Pro

ASP Scripts

FORGOT PASSWORD

One common problem with having a secure website is that occassionally members will lose or forget their login password. Well, if you collect their email address when they first register, this is an easy problem to handle. You can simply include a "Forgot Password" where the user enters the email address that they registered with and their password will be sent to them immediately.

The first thing you need to do is create a database called MyDatabase. Then create a table called tblUsers with these fields:
ID - autonumber
fUsername - text field
fPassword - text field
fEmail - text field
fDateEntered - date/time field

Now, create a page called password.asp page with the code below

<form name="Password" method="post" action="confirm.asp">
<table width="100%">
<tr><td>Email:</td>
<td><input type="text" name="Email" size="50">
<input type="submit" name="Submit" value="Submit">
</td></tr></table>
</form>

Next, create a page called confirm.asp with the code below:

<%
DIM strEmail
strEmail = Request.Form("Email")

IF strEmail <> "" THEN
%>
<!--#INCLUDE VIRTUAL="/includes/connection.asp"-->
<%
DIM mySQL, objRS
mySQL = "SELECT fEmail,fPassword FROM tblMembers WHERE fEmail = '" & strEmail & "'"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, objConn

IF objRS.EOF THEN
Response.Write "That email address was not found in our database. Please click Back on your browser and enter the email address you registered with."
ELSE
DIM strPassword
strPassword = objRS("fPassword")

DIM mail, objMail
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.From = "email@yourdomain.com"
objMail.Subject = "Password"
objMail.To = strEmail
objMail.Body = "Here is your login password: " & strEmail
objMail.Send
Set objMail = nothing

Response.Write "Your password has been sent to your email address."
END IF

ELSE
Response.Write "Please click Back on your browser and enter the email address you registered with."
END IF
%>

In this example, we are using the CDONTS email component to send our email. You can easily replace this with a different email component script like ASPMail or ASPEmail. That's all there is to it. Now, you have a fully automated Forgot Password tool that your website members can use anytime without hassle. That's customer service!

< Back to ASP Scripts


 

 

Main Menu
Home
ASP Scripts
ASP Tutorials
JavaScripts
Awards
Contact Us

Email This Page

Other Resources
ASP Web Hosting
Search Engine Submission
Programming Help

 

 

 

Other ASP Web Sites

Site Map

 

Last Updated:
06 July 2008