public ActionResult ResetPassword(ResetPassword model) { try { if (ModelState.IsValid) { BTourGuideOp tourOp = new BTourGuideOp(); List<AUser> users = tourOp.GetUsers(); // hasing the resetToken from the url HashComputer hashComp = new HashComputer(); string hashedResetToken = hashComp.GetPasswordHashAndSalt(model.ReturnToken); // Checking if the hash matches the resetToken from the DB AUser user = users.FirstOrDefault(u => u.ResetToken == hashedResetToken); if (user != null) { // password salting & hashing PasswordManager passMan = new PasswordManager(); string salt = null; string passwordHash = passMan.GeneratePasswordHash(model.Password, out salt); user.UserPassword = passwordHash; user.Salt = salt; user.ResetToken = null; tourOp.EditUser(user); ViewBag.Message = "Successfully Changed"; } else { ViewBag.Message = "Something went wrong!"; } } return View(model); } catch(Exception e) { TempData["Exception"] = "" + e.Message; return View(); } }
public ActionResult ResetPassword(string rt) { ResetPassword model = new ResetPassword(); model.ReturnToken = rt; return View(model); }