You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
3.0 KiB
Plaintext

First, you will need to create your database in MS Access 97 or 2000. Name your database "membersdb.mdb". Create the table "MEMBERS" with the fields USERNAMES, EMAIL & PASSWORD. Second, create "EnterEmail.htm" to let the visitor enter their email if they are registered with your database. For this example I am using the database I created in MS Access 2000.
<!-- Begin --->
<form method="POST" action="EmaiPassword.asp">
E-mail Address:<input type="text" name="email" size="30">
<p><input type="submit" value="Send it"></p>
</form>
<!-- End --->
Finally, we are going to create the ASP file that will verify the email address in the Access database and email the password. Call the file "EmailPassword.asp"
<% ' Begin %>
<%@ LANGUAGE="VBSCRIPT" %>
<% Option Explicit %>
<%
Dim DATA_PATH, Conn, DataRecords, email, user, pass, sendmail
'Maps to database. Change to your database path.
DATA_PATH=Server.Mappath("membersdb.mdb")
' Create and intiate data connection
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.ConnectionTimeout = 15
Conn.CommandTimeout = 30
Conn.Open "DBQ=" & DATA_PATH & ";Driver={Microsoft Access Driver (*.mdb)}; DriverId=25;MaxBufferSize=8192;Threads=20;", "admin", "password"
Set DataRecords = Server.CreateObject("ADODB.Recordset")
email=request.form("email")
'The magic query to look for registered members in the database
DataRecords.Open "SELECT * FROM MEMBERS WHERE email = '" & email & "'", Conn, 0, 1
%>
<head>
<title>Send Password</title>
</head>
<body>
<%
'checks if email address exists in the database before sending a message.
if DataRecords.EOF then
%>
<table border="0" cellPadding="0" cellSpacing="1" width="540">
<tr>
<td class="title-err" bgcolor="#FF0000"><font color="#FFFFFF"><b>Invalid
Email Address</b></font></td>
</tr>
</table>
<p><span class="text-err">We could not find</span><span class="text3b"> <%=email%></span>
<span class="text-err"> in our database.</span></p>
<% Else %>
<%
'sets variables
email = request.form("email")
'chooses username and password from database that correspond to submitted email address.
user = DataRecords.Fields("username")
pass = DataRecords.Fields("password")
Set sendmail = Server.CreateObject("CDONTS.NewMail")
'put the webmaster address here
sendmail.From = "support@yourdomain.com"
'The mail is sent to the address entered in the previous page.
sendmail.To = email
'Enter the subject of your mail here
sendmail.Subject = "Membership Login Information"
'This is the content of thr message.
sendmail.Body = "Per your request your account login information is: " & vbCrlf & vbCrlf _
& "Username=" & user & vbCrlf _
& "Password=" & pass & vbCrlf
'this sets mail priority.... 0=low 1=normal 2=high
sendmail.Importance = 3
sendmail.Send
%>
<p class="text2">We just sent your login information to <%=email%>.<br>
You should receive it shortly.</p>
<%
' Close Data Access Objects and free connection variables
Conn.Close
Set DataRecords = Nothing
Set Conn = Nothing
Set sendmail = Nothing
%>
<%end if%>