using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Data; using System.Net.Mail; public partial class Login_Forgot_Password : System.Web.UI.Page { public string pwd { get; set; } public string email { get; set; } protected void Page_Load(object sender, EventArgs e) { DbConnection.connect(); } protected void Btn_R_Password_Click(object sender, EventArgs e) { Password_Check(); } public void Password_Check() { try { string username = Txt_Uname.Text; string mobile = Txt_M_Number.Text; SqlCommand cmd = new SqlCommand("select Password,Email from Login where Username=@username and Mobile=@mobile", DbConnection.mCon); cmd.Parameters.Add("@username", SqlDbType.VarChar).Value = username; cmd.Parameters.Add("@mobile", SqlDbType.VarChar).Value = mobile; SqlDataAdapter madp = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); madp.Fill(dt); if (dt.Rows.Count > 0) { pwd = dt.Rows[0][0].ToString(); email = dt.Rows[0][1].ToString(); MailMessage m = new MailMessage(); m.To.Add(new MailAddress(email)); m.From = new MailAddress("ravee@gmail.com"); m.Subject = "Password Recovery"; m.IsBodyHtml = true; m.Body = "Dear User,<p />Please use the following password to login.<p />Password : " + pwd + "<p />WebMaster,<br />PhoneBook.Com"; SmtpClient smtp = new SmtpClient("smtp.gmail.com",587); smtp.Send(m); Lbl_Msg.Text = "Your password was mailed to you. Please use that password and <a href="../login.aspx">login</a>"; Txt_Uname.Text = Txt_M_Number.Text = ""; } else { Lbl_Msg.Text = "Please Enter a Valid User Name & Mobile Number"; } } catch { Lbl_Msg.Text = "Please Enter a Valid User Name & Mobile Number"; } } protected void Btn_Cancel_Click(object sender, EventArgs e) { Txt_M_Number.Text = Txt_Uname.Text = ""; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)