Results 1 to 4 of 4

Thread: send password - message

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    8

    send password - message

    I have a forgot password page that successfully sends the password to a user. All I want to do is add a line of text that says "your email has been sent" when the request is valid and "your email address was not found" if the request fails . I want to be able to put that message in a row of the table. I am very new to asp.net and don't know how to do that. Here is the code that I have created ( I have not included the table and form information) that successfully sends the password:

    Sub Button1_Click(sender As Object, e As EventArgs)
    Dim lostpwd AS string
    Dim mailMessage As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
    Dim passwordDS AS System.Data.DataSet = GetEmail(email.Text)
    If passwordDS.Tables(0).Rows.Count = 1 Then
    lostpwd = passwordDS.Tables(0).Rows(0).Item(“pwd”).ToString
    mailMessage.From = "[email protected]"
    mailMessage.To = email.Text
    mailMessage.Subject = "Lost Password"
    mailMessage.BodyFormat = System.Web.Mail.MailFormat.Text
    mailMessage.Body = "here is your password: " + lostpwd + chr(13) + "if you have questions, please contact the site administrator"
    System.Web.Mail.SmtpMail.SmtpServer = "ciruelo.xxxx.xx"
    System.Web.Mail.SmtpMail.Send(mailMessage)
    Else
    End if

    End Sub

    Function GetEmail(ByVal email As String) As System.Data.DataSet
    Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\Inetpub\wwwroot\xxxxx\xxxx.mdb"
    Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)

    Dim queryString As String = "SELECT [authors].[pwd] FROM [authors] WHERE ([authors].[email] = @email)"
    Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
    dbCommand.CommandText = queryString
    dbCommand.Connection = dbConnection

    Dim dbParam_email As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
    dbParam_email.ParameterName = "@email"
    dbParam_email.Value = email
    dbParam_email.DbType = System.Data.DbType.String
    dbCommand.Parameters.Add(dbParam_email)

    Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
    dataAdapter.SelectCommand = dbCommand
    Dim dataSet As System.Data.DataSet = New System.Data.DataSet
    dataAdapter.Fill(dataSet)

    Return dataSet
    End Function

    Thanks alot

  2. #2
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    For starters I would tend to use a datareader for web pages 9 times out of 10 purely from a speed point of view but thats not a crucial point.

    dim RetrieveMsg as string 'page wide variable that both functions can access

    Sub Button1_Click(sender As Object, e As EventArgs)

    if GetEmail(email.Text) then
    Dim lostpwd AS string
    Dim mailMessage As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
    mailMessage.From = "[email protected]"
    mailMessage.To = email.Text
    mailMessage.Subject = "Lost Password"
    mailMessage.BodyFormat = System.Web.Mail.MailFormat.Text
    mailMessage.Body = "here is your password: " + RetrieveMsg + chr(13) + "if you have questions, please contact the site administrator"
    System.Web.Mail.SmtpMail.SmtpServer = "ciruelo.xxxx.xx"
    System.Web.Mail.SmtpMail.Send(mailMessage)
    Else
    label1.text = RetrieveMsg
    End if

    End Sub

    Function GetEmail(ByVal email As String) As boolean
    Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\Inetpub\wwwroot\xxxxx\xxxx.mdb"
    Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)
    Dim queryString As String = "SELECT [authors].[pwd] FROM [authors] WHERE ([authors].[email] = @email)"
    Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
    dbCommand.CommandText = queryString
    dbCommand.Connection = dbConnection
    Dim dbParam_email As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
    dbParam_email.ParameterName = "@email"
    dbParam_email.Value = email
    dbParam_email.DbType = System.Data.DbType.String
    dbCommand.Parameters.Add(dbParam_email)
    dim dr as System.Data.OleDb.oledbdatareader
    try
    conn.open
    dr = cmd.executereader
    if dr.read then
    RetrieveMsg = dr.item("pwd").tostring
    return true
    else
    RetrieveMsg = "Sorry but your email address was not found!"
    return false
    finally
    conn.close
    end try
    End Function

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    8
    thanks very much musician for your response. I have a couple of questions:

    1. mailMessage.Body = "here is your password: " + RetrieveMsg + chr(13) + "if you have questions, please contact the site administrator"

    the RetrieveMsg replaces 'lostpwd' right?

    2. Else
    label1.text = RetrieveMsg
    End if

    Do I need to create a label with id= label1 and place it on my page for the RetrieveMsg?

    3. Lastly, I would also like to place a message on the page that says "your email has been successfullly sent" when the page is valid. How would I do that?

    Many thanks

  4. #4
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    1. Yes. when the password is successfully retrieved it will be assigned to that variable.

    2. I used a label in that example. you can use a Literal or a Label or just response.write but I would prefer to use an asp.net control for more control over the output. You can call the control anything you want just alter the code accordingly.

    3. Just use the same label or whatever control you have on the page and set the text property with the text you want to display.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width