One common problem on websites that have a secure member area is that registered members will occasionally forget their login password. Well, there is a quick and easy way to handle this by offering your members a Forgot Password tool. Members simply enter the email address they used when registering with your website into a form and then their password will be emailed to them right away.
To do this, create a database called MyData and a table called tblMembers with these fields:
ID – autonumber
fUsername – text field
fPassword – text field
fEmail – text field
fDateEntered – date/time field
Now, create a page called /LostPassword.asp page with the code below
<form name="ForgotPassword" method="post" action="confirm.asp"> Email: <input type="text" name="Email" size="50"> <input type="submit" name="Submit" value="Submit"> </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 " Response.Write "click Back on your browser and enter the email address " Response.Write "you registered with." ELSE DIM strPassword strPassword = objRS("fPassword") DIM mail, objMail Set objMail = Server.CreateObject("CDONTS.NewMail") objMail.From = "email@example.com" objMail.Subject = "Forgotten 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 " Response.Write "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 24/7 without any hassle!