public ActionResult ChangePassword(EmployeePassword model) { try { if (string.IsNullOrEmpty(model.password)) { ModelState.AddModelError("password", "Old password expected"); } if (string.IsNullOrEmpty(model.nPassword)) { ModelState.AddModelError("nPassword", "New password expected"); } if (string.IsNullOrEmpty(model.nlPassword)) { ModelState.AddModelError("nlPassword", "Password expected"); } model.password = MD5Helper.EncodeMD5(model.password); model.nPassword = MD5Helper.EncodeMD5(model.nPassword); model.nlPassword = MD5Helper.EncodeMD5(model.nlPassword); EmployeeBLL.ChangePassword(model.Id, model.password, model.nPassword, model.nlPassword); return(RedirectToAction("Index", "Dashboard")); } catch (Exception ex) { ModelState.AddModelError("", ex.Message + ":" + ex.StackTrace); return(View(model)); } }
public ActionResult ChangePassword(string userID, string oldPassword, string newPassword, string confirmPassword) { //kiểm tra hợp lệ dữ liệu if (string.IsNullOrEmpty(userID)) { ModelState.AddModelError("userID", "UserID is invalid"); } if (string.IsNullOrEmpty(oldPassword)) { ModelState.AddModelError("oldPassword", "Old Password is invalid"); } if (string.IsNullOrEmpty(newPassword)) { ModelState.AddModelError("newPassword", "New Password is invalid"); } if (string.IsNullOrEmpty(confirmPassword)) { ModelState.AddModelError("confirmPassword", "Confirm Password is invalid"); } if (!newPassword.Equals(confirmPassword)) { ModelState.AddModelError("notMatch", "New Password and Confirm Password must match"); } Employee existEmployee = EmployeeBLL.GetEmployee(Convert.ToInt32(userID)); oldPassword = Encode.EncodeMD5(oldPassword); newPassword = Encode.EncodeMD5(newPassword); if (!existEmployee.Password.Equals(oldPassword)) { ModelState.AddModelError("wrongPassword", "Password is wrong"); } if (ModelState.IsValid) { //Lưu thay đổi if (EmployeeBLL.ChangePassword(Convert.ToInt32(userID), newPassword)) { return(RedirectToAction("Index", "Dashboard")); } } return(View()); }