public ActionResult ResetPassword(ResetPasswordViewModel2 model) { if (ModelState.IsValid) { // Validate that the user exists User u = context.Users.FirstOrDefault(us => us.EmailAddress.Equals(model.Email)); if (u == null) { return(RedirectToAction("Index", "Account")); } // Make sure the link is not expired if (u.ResetExpiresAt < DateTime.Now) { ModelState.AddModelError("expired", "Denne nøgle er udløbet."); return(RedirectToAction("ResetPassword1", "Account")); } if (!PasswordHash.ValidatePassword(model.ResetKey, u.ResetKey)) { ModelState.AddModelError("illegalKey", "Ugyldig nøgle."); return(RedirectToAction("ResetPassword1", "Account")); } u.ResetExpiresAt = DateTime.Now; u.ResetKey = null; u.Pw = PasswordHash.CreateHash(model.Password); TempData["message"] = "Log ind med dit nye kodeord."; return(RedirectToAction("Index", "Account")); } return(View("ResetPasswordStep1", model)); }
public ActionResult ResetPassword2(string key, string email) { // Validate that the user exists User u = context.Users.FirstOrDefault(us => us.EmailAddress.Equals(email)); if (u == null) { return(RedirectToAction("Index", "Account")); } // Make sure the link is not expired if (u.ResetExpiresAt < DateTime.Now) { ModelState.AddModelError("expired", "Denne nøgle er udløbet."); return(RedirectToAction("ResetPassword1", "Account")); } if (!PasswordHash.ValidatePassword(key, u.ResetKey)) { ModelState.AddModelError("expired", "Ugyldig nøgle er udløbet."); return(RedirectToAction("ResetPassword1", "Account")); } ResetPasswordViewModel2 vm = new ResetPasswordViewModel2() { ResetKey = key, Email = email }; return(View("ResetPasswordStep1", vm)); }