How to get password sent to user with Forgot Password ASP page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jerrydigital
    New Member
    • Oct 2008
    • 67

    #1

    How to get password sent to user with Forgot Password ASP page

    Hi,

    I am working on a forgotpassword. asp page. I would like the user to enter their email address, and click submit. Upon submit, an email will be sent to the user's email address provided with the "password" they registered with.

    I have posted my code below. However, I get an error on line 31:

    Code:
    Message = "You're password is:" & <%=objRS("Password" )%>
    The input name="email" on the html form that leads to this asp page.

    Thanks for any input

    Code:
    <%@ Language=VBScript %>
    <% Option Explicit %>
    <!--#include virtual="/adovbs.inc"-->
    <html>
    <head><title>Edit User Information</title></head>
    <%
    Dim oConn, oRs
    Dim connectstr, sDSNDir, tablename
    Dim db_name, db_username, db_userpassword
    Dim dsn_name
    
    dsn_name = "jerry_db.dsn"
    tablename = "tblRegister"
    db_username = "****"
    db_userpassword = "****"
    
    sDSNDir = Server.MapPath("/_dsn")
    connectstr = "filedsn=" & sDSNDir & "/" & dsn_name
    
    Set oConn = Server.CreateObject("ADODB.Connection")
    oConn.Open connectstr
    
    Dim EmailFrom
    Dim EmailTo
    Dim Subject
    Dim Message
    
    EmailFrom = "jerry@digital.com"
    EmailTo = Trim(Request.Form("email"))
    Subject = "Here is your Password"
    Message = "You're password is:" & <%=objRS("Password" )%>
    
    
    Dim validationOK
    validationOK=true
    If (validationOK=false) Then Response.Redirect("index.html")
    
    Dim Body
    Body = Body & message
    
     
    Dim mail
    Set mail = Server.CreateObject("CDONTS.NewMail") 
    mail.To = EmailTo
    mail.From = EmailFrom
    mail.Subject = Subject
    mail.Body = Body
    mail.Send 
    
    
    Dim objRS, bolFound, strEmail
    strEmail = Request.Form("email")
    
    If ((Request.Form("email") = "") Then
    
    oConn.Close
    Set oConn = Nothing
    %>
    You must enter values for all the fields. Either hit the "back" button or click <a hred="login.html"> here to log in</a>
    <%
    Else
    Set objRS = Server.CreateObject("ADODB.Recordset")
    objRS.Open "tblRegister", oConn, , adLockOptimistic, adCmdTable
    bolFound = False
    
    Do Until objRS.EOF OR bolFound
    If (StrComp(objRS("Email"), strEmail, _
    vbTextCompare) = 0) Then
    
    BolFound = True
    Else
    objRS.MoveNext
    End If
    Loop
    
    If Not bolFound Then
    objRS.Close
    Set objRS = Nothing
    oConn.Close
    Set oConn = Nothing
    Response.Write "<a href='login.html'>"
    Response.Write "Invalid Email Address.<p>"
    Response.Write "</a>"
    Response.End
    End If
    	objRS("Email") = Request.Form("email")
    	
    objRS.Update
    objRS.Close
    Set objRS=Nothing
    End If
    oConn.Close
    Set oConn = Nothing
    %>
    Your password has been sent to your email account.  Please click <a href="login.html">here</a> to log in to your account.
    </body>
    </html>
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    Originally posted by jerrydigital
    I have posted my code below. However, I get an error on line 31:

    Code:
    Message = "You're password is:" & <%=objRS("Password" )%>
    the code <%=%> is shorthand for "response.write " - it writes the contents to the webpage. This is not what you want, you want to append the contents to the variable "Message". Try this:
    Code:
    Message = "You're password is:" & objRS("Password" )
    Let me know if this helps.

    Jared

    Comment

    • jerrydigital
      New Member
      • Oct 2008
      • 67

      #3
      Thank you for your input. It work to a degree.

      I am able to email the password to the users but unfortunately, the email has the same password for all users.

      How do I get the system to send the correct password to each user in my database?

      Below is the code I am using:

      Code:
      <%@ Language=VBScript %>
      <% Option Explicit %>
      <!--#include virtual="/adovbs.inc"-->
      <html>
      <%
      Dim oConn, objRS
      Dim connectstr, sDSNDir, tablename
      Dim db_name, db_username, db_userpassword
      Dim dsn_name
      
      dsn_name = "access_db.dsn"
      tablename = "tblRegister"
      db_username = "****"
      db_userpassword = "****"
      
      sDSNDir = Server.MapPath("/_dsn")
      connectstr = "filedsn=" & sDSNDir & "/" & dsn_name
      
      Set oConn = Server.CreateObject("ADODB.Connection")
      oConn.Open connectstr
      Set objRS = Server.CreateObject("ADODB.Recordset")
      objRS.Open "tblRegister", oConn, , adLockOptimistic, adCmdTable
      	
      Dim EmailFrom
      Dim EmailTo
      Dim Subject
      Dim Message
      
      EmailFrom = "jerry@jerry.com"
      EmailTo = Trim(Request.Form("email"))
      Subject = "Your Password"
      Message = "You're password is:" & objRS("Password" )
      
      
      Dim validationOK
      validationOK=true
      If (validationOK=false) Then Response.Redirect("index.html")
      
      Dim Body
      Body = Body & message
      
      Dim mail
      Set mail = Server.CreateObject("CDONTS.NewMail") 
      mail.To = EmailTo
      mail.From = EmailFrom
      mail.Subject = Subject
      mail.Body = Body
      mail.Send 
      
      Response.Write "Your password has been emailed to you."
      Response.Write "<a href='login.html'>"
      Response.Write "Click here to log in to your account"
      Response.Write "</a>"
      	
      objRS.Close
      Set objRS = Nothing
      oConn.Close
      Set oConn = Nothing
      %>
      </body>
      </html>

      Comment

      • jerrydigital
        New Member
        • Oct 2008
        • 67

        #4
        Well, I figured it out. I now am able to email users their forgotten passwords if they enter a valid email address. All I had to do is add the following code to my post #3 code. I deleted the dim objRS at the top and entered it will the rest of the code below after the connection was opened. I guess by validating that the email is in my database, it also matches up the proper password for the email supplied.

        Code:
        Dim objRS, bolFound, strEmail
        strEmail = Request.Form("email")
        
        If strEmail = "" Then
        oConn.Close
        Set oConn = Nothing
        Response.Write "<a href='forgot.html'>"
        Response.Write "You must enter a email address"
        Response.Write "</a>"
        Response.End
        End If
        
        Set objRS = Server.CreateObject("ADODB.Recordset")
        objRS.Open "tblRegister", oConn, , , adCmdTable
        bolFound = False
        
        Do While Not (objRS.EOF OR bolFound)
        If (StrComp(objRS("Email"), strEmail, vbTextCompare) = 0) Then
        BolFound = True
        Else
        objRS.MoveNext
        End If
        Loop
        
        If Not bolFound Then
        objRS.Close
        Set objRS = Nothing
        oConn.Close
        Set oConn = Nothing
        Response.Write "<a href='forgot.html'>"
        Response.Write "Invalid Email Address.<p>"
        Response.Write "</a>"
        Response.End
        End If

        Thank you again for all of your help. I wouldn't have been able to get this far on my web site design without this forum. I hope you all continue to provide such valuable information for years to come.

        Jerry

        Comment

        Working...