public ActionResult ChangePassword(StudentChangePasswordVM model) { if (!ModelState.IsValid) { return View(); } if (model.NewPassword != model.NewPasswordRepeat) { ModelState.AddModelError("Error", "New password dont match"); return View(model); } UserRepository<Student> stuRepo = new UserRepository<Student>(); Student student = stuRepo.GetByID(model.StudentID); Passphrase hash = PasswordHasher.Hash(model.OldPassword); if (PasswordHasher.Equals(model.OldPassword, student.Salt, student.Hash)) { Passphrase hash2 = PasswordHasher.Hash(model.NewPassword); student.Salt = hash2.Salt; student.Hash = hash2.Hash; stuRepo.Save(student); } else { ModelState.AddModelError("Error", "Old password dont match"); return View(model); } return RedirectToAction("Index", "Student"); }
public ActionResult ChangePassword() { StudentChangePasswordVM model = new StudentChangePasswordVM(); UserRepository<Student> stuRepo = new UserRepository<Student>(); Student student = stuRepo.GetByID(Models.AuthenticationManager.LoggedUser.ID); model.StudentID = student.ID; return View(model); }