public ActionResult ResetPassword(string id) { //Verify the reset password link //Find account associated with this link //redirect to reset password page if (string.IsNullOrWhiteSpace(id)) { return(HttpNotFound()); } using (InformationDetailsEntities dc = new InformationDetailsEntities()) { var user = dc.UserLogins.Where(a => a.ResetPasswordCode == id).FirstOrDefault(); if (user != null) { ResetPasswordModel model = new ResetPasswordModel(); model.ResetCode = id; return(View(model)); } else { return(HttpNotFound()); } } }
public ActionResult ResetPassword(ResetPasswordModel model) { var message = ""; //if (ModelState.IsValid) //{ if (model.NewPassword == model.ConfirmPassword) { using (InformationDetailsEntities dc = new InformationDetailsEntities()) { var user = dc.UserLogins.Where(a => a.ResetPasswordCode == model.ResetCode).FirstOrDefault(); if (user != null) { user.password = Crypto.Hash(model.NewPassword); user.ResetPasswordCode = ""; dc.Configuration.ValidateOnSaveEnabled = false; dc.SaveChanges(); message = "New password updated successfully"; } } } else { message = "New password and confirm password does not match"; } //} //else //{ // message = "Something invalid"; //} ViewBag.Message = message; return(View(model)); }
public ActionResult ForgotPassword(string EmailID) { //Verify Email ID //Generate Reset password link //Send Email string message = ""; bool status = false; using (InformationDetailsEntities dc = new InformationDetailsEntities()) { var account = dc.UserLogins.Where(a => a.EmailAddress == EmailID).FirstOrDefault(); if (account != null) { //Send email for reset password string resetCode = Guid.NewGuid().ToString(); SendVerificationLinkEmail(account.EmailAddress, resetCode, "ResetPassword"); account.ResetPasswordCode = resetCode; //This line I have added here to avoid confirm password not match issue , as we had added a confirm password property //in our model class in part 1 dc.Configuration.ValidateOnSaveEnabled = false; dc.SaveChanges(); message = "Reset password link has been sent to your email id."; } else { message = "Account not found"; } } ViewBag.Message = message; return(View()); }