public ActionResult ChangePassword(ChangePasswordViewModel inModel) { if(inModel.Password != inModel.ConfirmPassword) { ModelState.AddModelError("", "The passwords do not match"); return View(inModel); } RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(); if (String.IsNullOrEmpty(recaptchaHelper.Response)) { ModelState.AddModelError("", "Captcha answer cannot be empty"); return View(inModel); } RecaptchaVerificationResult recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse(); if (recaptchaResult != RecaptchaVerificationResult.Success) { ModelState.AddModelError("", "Incorrect captcha answer"); return View(inModel); } try { var user = _ctx.UserProfiles.Find(inModel.UserId); if (inModel.UserName == user.UserName) { WebSecurity.ResetPassword(inModel.Token, inModel.Password); WebSecurity.Login(inModel.UserName, inModel.Password, true); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", "The user name does not match our records"); return View(inModel); } } catch { throw new Exception("Change Password forgery"); } }
public ActionResult ChangePassword(string token) { var userId = WebSecurity.GetUserIdFromPasswordResetToken(token); if (userId > 0) { var outModel = new ChangePasswordViewModel{ UserId = userId, Token = token }; return View(outModel); } else { return View("Error"); } }