title: Forgot password asp.net using database
body: <p>I want to do a link with a forgot password. I did the part where I send the message to the email but I don't really get how to take the password from SQL database and send it on email.</p>
  
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
  {
      try
      {
          SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["AMPRConnectionString"].ConnectionString);
          con.Open();
          SqlDataReader myReader = null;
          SqlCommand myCommand = new SqlCommand("select * from logare where email='" + TextBox1.Text + "'", con);
  
          SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
          client.EnableSsl = true;
          client.DeliveryMethod = SmtpDeliveryMethod.Network;
          client.UseDefaultCredentials = false;
          client.Credentials = new NetworkCredential("*******", "*****");
  
          MailMessage mailMessage = new MailMessage();
          mailMessage.To.Add(TextBox1.Text);
          mailMessage.From = new MailAddress("******");
          mailMessage.Subject = ("Password recoverd");
          mailMessage.Body = "Dear " + TextBox1.Text + ", Your Password is  "+ ? ;
          client.Send(mailMessage);
          ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('Email has been sent succesfully !');", true);
      }
      catch (Exception ex)
      {
          Response.Write("Could not send email" + ex.Message);
      }
  }
  </code></pre>