public ActionResult ChangePassword(ChangePasswordViewModel model) { if (!ModelState.IsValid) { return View(model); } var username = User.Identity.Name; if ((CheckUser(username, model.OldPassword) == 1) && (model.NewPassword == model.ConfirmPassword) && (username != null)) { RNGCryptoServiceProvider csprng = new RNGCryptoServiceProvider(); byte[] salt = new byte[SALT_BYTE_SIZE]; csprng.GetBytes(salt); var hashedPassword = Hash.CreateHash(model.NewPassword, salt); db.ChangePassword(username,hashedPassword, salt); return RedirectToAction("Logout"); } else { ViewBag.Error = "Incorrect Information!"; return View(); } }
public async Task<ActionResult> ChangePassword(ChangePasswordViewModel model) { if (!ModelState.IsValid) { return View(model); } var result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword); if (result.Succeeded) { var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); if (user != null) { await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); } return RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess }); } AddErrors(result); return View(model); }