C# .NET - Send email to user for password reset

Asked By Muthu Kumar on 26-Jun-12 07:29 AM
if the user forget their password 
how  can i  send reset password link to user mail id .that will use onle one time , after one time use this link will dispose and say that this link is wrong.

Thanks in advance
Lalit M replied to Muthu Kumar on 26-Jun-12 07:35 AM
Use this code for password reset.
DataSet ds=new DataSet();

ds=fp.viewdatabase("select password from login where
username='"+txtuser.Text+"' and
securityquest='"+dropsecurity.SelectedItem.Text+"' and
MailMessage msg = new MailMessage();
msg.From = new MailAddress("sender@abc.com");
msg.To.Add(new MailAddress(txtaltmai.Text.Trim()));  // receiver   mail
msg.Subject ="Your correct password given";

msg.Body = "your password is'"+ds.Tables[0].Rows[0]["password"].ToString()
msg.IsBodyHtml = true;
SmtpClient sc = new SmtpClient("smtp.gmail.com", 587);
System.Net.NetworkCredential basicAuthentication = new
System.Net.NetworkCredential("sender@abc.com", "developers_choice");
sc.EnableSsl = true;
sc.UseDefaultCredentials = false;
sc.DeliveryMethod = SmtpDeliveryMethod.Network;
sc.Credentials = basicAuthentication;
Response.Write("Your password has been send to secondary

catch (Exception ex)

Read more options.

Using MVC
dipa ahuja replied to Muthu Kumar on 26-Jun-12 02:28 PM
If you are using custome password recovery the just have to send the mail to the user that your password is:

protected void btnSent_Click(object sender, EventArgs e)
  string toEmailAddress = "UserToWhomSendPassword@gmail.com";
  string GmailId = "xxx@gmail.com";
  string password = "xxx";
  SqlDataAdapter da = new SqlDataAdapter("Select uname,password from user where username='" + TextBox1.Text
  + "'", "ConnectionSTring");
  DataTable dt = new DataTable();
  string bodyMsg = "Your Username :" + dt.Rows[0]["uname"] + "and passowrd:" + dt.Rows[0]["password"].ToString();
  MailMessage mail = new MailMessage();
  mail.From = new MailAddress(GmailId);
  mail.Subject = txtSubject.Text;
  mail.Body = bodyMsg;
  mail.IsBodyHtml = true;
  SmtpClient smtp = new SmtpClient("smtp.gmail.com");
  smtp.EnableSsl = true;
  smtp.UseDefaultCredentials = false;
  smtp.Credentials = new System.Net.NetworkCredential(GmailId, password);
RAJASEKHAR RAJENDRAN replied to Muthu Kumar on 27-Jun-12 04:03 AM
Hi muthu,

Refer the below links, which will solve your issue.


Thanks & Regards,