public ActionResult ForgotPassword(ForgotPassword model) { if (model.Email == null) { ModelState.AddModelError("", "User email id is required"); } else { //if (WebSecurity.UserExists(model.Email)) //{ System.Data.DataTable dt = new System.Data.DataTable(); dt = BLObj.GetUserbyEmail(model.Email); //dt = bl.GetEmailId(model.UserName); if (dt.Rows.Count == 1) { string UserName = dt.Rows[0][1].ToString(); var token = WebSecurity.GeneratePasswordResetToken(UserName); //bl.SendMail(EmailID, model.UserName, token); htmlFilePath = Server.MapPath(Constants.ResetPasswordHTMLTemplate); BLObj.SendMail(model.Email, UserName, token, htmlFilePath); ViewBag.Success = "Your Token has been mail on your Email Account.Use it to reset password,follow provided link in mail to go to reset password page"; } else { //ModelState.AddModelError("", "No EmailId"); ModelState.AddModelError("", "No User attached with this Email Address!"); } } return View(); }
public ActionResult ForgotPassword(ForgotPassword model) { //var mod = new ForgotPassword(); if (model.UserName == null) { ModelState.AddModelError("", "User Name Required"); } else { if (WebSecurity.UserExists(model.UserName)) { System.Data.DataTable dt = new System.Data.DataTable(); VishwaPress.BusinessLayer.BLControllers.BL_Account bl = new BusinessLayer.BLControllers.BL_Account(); dt = bl.GetEmailId(model.UserName); if (dt.Rows.Count == 1) { string EmailID = dt.Rows[0][0].ToString(); var token = WebSecurity.GeneratePasswordResetToken(model.UserName,5); bl.SendMail(EmailID, model.UserName, token); ViewBag.Success = "Your Token has been mail on your Email Account.Use it to reset password,follow provided link in mail to go to reset password page"; } else { ModelState.AddModelError("", "No EmailId"); } } else { ModelState.AddModelError("", "invalid User Name !!"); } } return View(model); }