Forgotten Password Reminder Example

Who this tutorial is for

How does it work?

This lesson is easy. (weren't the others?)

Here we will make a tiny modification to the Email Confirmation. So I'm assuming you have followed Lesson 4 and you're ready to unleash you're new found knowledge in yet more exciting directions.

Ok, here goes. The user enters his/her UserID and hits submit. The second page checks whether the user exists on the member database. If yes, an email is sent by this page. If no, the user is told that he doesn't exist (what a bummer!).

We will also look at some ways of customising the content of the email.

Try the demo

Steps

1 Create a page for the input form
2 Create a Recordset on Confirmation Page - UltraDev will do this for you
3 A teeny weeny bit of code to decide if we know ThisUser
4 Create a page to say 'you do not exist!'
5 Customise the code for sending email (eg. JMail, CDONTS)

As before, you will need to find out from your web host which mail programs are available to you. The code in this demo and example is JMail. The code for CDONTS is similar (see an example).

1 Create a page for the input form

By now you should be able to do this in your sleep. For the purposes of this tutorial though please try and stay awake!

You need a form with just one textbox for the UserID and a submit button. In the Action box you need the Confirmation Page (step 2) and the Method is Post.

2 Create a Recordset on the Confirmation Page

Now to the Confirmation Page. This page does 3 things - (1) check whether the user exists on the database (2) redirect if the user does not exist and (3) send the email if the user does exist.

In previous lessons we passed data between pages by stuffing the UserID into a Session Variable. This is because it is likely that we would want to remember the visitor throughout his/her visit. For our current purpose we only want to remember the UserID until the second page - the page that sends out the email. So we will use Request.Form("UserID") instead.

Create a recordset rsThisUser exactly as in Lesson 3 except with Run-time Value as below.

This should give us a recordset with just one record, the record for ThisUser ... or nothing.

3 A teeny weeny bit of code to decide if we know ThisUser

Immediately following the code generated by UltraDev we want the following

to redirect if the user is not in our database.

4 Create a page to say 'you do not exist!'

This is the page to redirect to (in Step 3) - "passwordreminderfailed.asp". Perhaps with a link to a 'Register' page?

5 Customise the code for sending the email

You'll customise the email in the way you want to, so I shall only show you the principles here. And while we're at it check your version with the code I have used in the demo.

Use variables even though its sometimes not entirely necessary. eg. strUserID.
Retrieve data from the database with rsThisUser.Fields.Item("AnyField").Value
Put " around the text that you compose and join them with &.
vbNewLine will do the same job as a carriage return.

Again, remember that you will need to ask your web host which mail component they use (JMail, CDONTS etc) and some info specific to the configuration (eg. address of your local SMTP server).

See the code in this demo

Simple, isn't it?

Next time we'll look at:

Member Update - How registered users can maintain their own member details.
How to authenticate email address via an authentication link back.

Troubleshooting Tips
Write a Review of this Tutorial
Read Reviews

Please send comments to Hiran de Silva.

Home