/// <summary> /// To get Forget Password /// </summary> /// <param name="fpEntity">Object for getting password from database</param> /// <returns>System.Data.DataSet</returns> public DataSet GetEmailDetailsDAL(ForgetPasswordEntity fpEntity) { connection.Open(); DataSet ds = new DataSet(); try { SqlCommand cmd = new SqlCommand(Constants.sp_ForgetPassword, connection); //SqlParameter[] sparams = { new SqlParameter("@emailid", fpEntity.EmailId) }; //SqlDataReader dr= SqlHelper.ExecuteReader(connection, CommandType.StoredProcedure, Constants.sp_ForgetPassword, sparams); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@emailid", fpEntity.EmailId.ToString()); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(ds, "EmailDetails"); } catch (Exception) { // throw; } finally { connection.Close(); } return ds; }
/// <summary> /// Forget password method in Utility class /// </summary> /// <param name="forgotPasswordEntity">The forgot password entity.</param> /// <returns>System.Data.DataSet.</returns> public static DataSet ForgetPasswordJobSeeker(ForgetPasswordEntity forgotPasswordEntity) { try { ForgetPasswordDAL jobSeekerDAL = new ForgetPasswordDAL(); return jobSeekerDAL.GetEmailDetailsDAL(forgotPasswordEntity); } catch (Exception ex) { throw ex; } }
/// <summary> /// Handles the Click event of the Submit_Click control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void Submit_Click(object sender, EventArgs e) { try { DataSet dsForgetPassword = new DataSet(); ForgetPasswordEntity fpEntity = new ForgetPasswordEntity(); fpEntity.EmailId = txtEmailId.Text.ToString(); dsForgetPassword = Utility.ForgetPasswordJobSeeker(fpEntity); // Check if dataset is not null if (dsForgetPassword != null) { // Check if count rows grater than zero if (dsForgetPassword.Tables[0].Rows.Count > 0) { MailMessage email = new MailMessage(); email.From = new MailAddress(txtEmailId.Text); //Enter sender email address email.To.Add(txtEmailId.Text); //Destination Recipient e-mail address. email.Subject = "Your Forrget Password:"******"Hi,<br/>Your Username is: " + dsForgetPassword.Tables[0].Rows[0]["EmailId"] + "<br/><br/>Your Password is: " + dsForgetPassword.Tables[0].Rows[0]["Password"] + "<br/>"; email.IsBodyHtml = true; // SMTP SERVER DETAILS SmtpClient smtpc = new SmtpClient("smtp.gmail.com"); smtpc.Port = 587; smtpc.UseDefaultCredentials = false; smtpc.EnableSsl = true; smtpc.Credentials = new NetworkCredential("*****@*****.**", "@jacksparow"); smtpc.Send(email); lblMsg.Text = txtEmailId.Text + "Your password has been sent to your email address"; } else { lblMsg.Text = "This email address is not exist in our Database try again"; } } } catch (Exception ex) { lblMsg.Text = ex.Message.ToString(); } }