Click here to Skip to main content
15,887,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Requirement : For forgot password functionality, need to send email contains unique and one time use link to reset password.
I am able to send email with unique link created using GUID functionality. Now I want to make it one time use. How to do that?

What I have tried:

C#
protected void btnRECOVER_PASSWORD_Click(object sender, EventArgs e)
       {
           SendMail();
       }

C#
public void SendMail()
       {

           login = new NetworkCredential("leaves@nworks.co", "password");
           client = new SmtpClient("smtp.1and1.com");
           client.Port = Convert.ToInt32(25);
           client.EnableSsl = true;
           client.Credentials = login;
           msg = new MailMessage { From = new MailAddress("leaves@nworks.co", "nWorks Employee", Encoding.UTF8) };
           msg.To.Add(new MailAddress(this.TextBoxEmail_Mobile.Text));
           msg.Subject = "Recover Password For Your nWorks Leave Management Account";
           msg.CC.Add(new MailAddress("dipak.a.akhade9192@gmail.com"));
           //       msg.CC.Add(new MailAddress("*************user mail id*************"));
           string strBody = string.Empty;
           Guid code = Guid.NewGuid();

               strBody += "<html><head></head><body><p>Click the following link to recover your password.</p>";
               strBody += Environment.NewLine;


               strBody += "<form action='' method='POST' name='myForm1'><a href='http://localhost:19343/ResetPasswordForm.aspx'>'" + code.ToString() + "'</form><br>";


           strBody += "<br/>Thanks.</body></html>";

           msg.Body = strBody;

           msg.BodyEncoding = Encoding.UTF8;
           msg.IsBodyHtml = true;
           msg.Priority = MailPriority.Normal;
           msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
           client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
           string userstate = "sending.......";
           client.SendAsync(msg, userstate);

           string q1 = "insert into RecoverPwdStatus values(101,'" + code.ToString() + "');";
           MySqlCommand cmd1 = new MySqlCommand(q1, conn); conn.Open();
           MySqlDataReader rdr1 = cmd1.ExecuteReader(); conn.Close();

       }
Posted
Comments
Member 11914978 15-Feb-16 0:11am    
I am thinking to save that unique link in database across the user while sending email to him with the same link. As user clicks link for first time delete that link from database. If that link is not available in database and user wants to use it,redirect him to error page. But I don't know how to detect that link and user when someone clicks that link.

1 solution

Quote:
As user clicks link for first time delete that link from database.
To the href append that code. So, the url should look like...
http://localhost:19343/ResetPasswordForm.aspx?code=12345

Now when user clicks on this link, the page load event is fired. Inside page load retrieve the QueryString "code". Do whatever you want to do after that.
 
Share this answer
 
v2
Comments
Member 11914978 15-Feb-16 2:14am    
Thanks... I am trying same solution... but I want more than
two parameters... then what to do?
http://localhost:19343/ResetPasswordForm.aspx?code=12345&secondParam=6789
Member 11914978 15-Feb-16 3:30am    
But sir I have ResetPasswordForm.aspx page in my project.... if I am using http://localhost:19343/ResetPasswordForm.aspx?code=12345&secondParam=6789.... page not found error occurs.
Member 11914978 15-Feb-16 4:08am    
I used :
Member 11914978 15-Feb-16 3:28am    
But sir I have ResetPasswordForm.aspx page in my project.... if I am using http://localhost:19343/ResetPasswordForm.aspx?code=12345&secondParam=6789.... page not found error occurs.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900