protected bool ValidateModel(ChangePwdModel model) { if(!string.IsNullOrEmpty(model.NewPassword)) { bool containDigit = false; bool containLetter = false; string password = model.NewPassword; foreach (char c in password) { if (Char.IsDigit(c)) containDigit = true; else if (Char.IsLetter(c)) containLetter = true; } if(!containDigit || !containLetter) ModelState.AddModelError("NewPassword", "Поле 'Новый пароль' должен содержать буквы и цифры"); } return ModelState.IsValid; }
public ActionResult ChangePwd() { ChangePwdModel model = new ChangePwdModel(); return View(model); }
public ActionResult ChangePwd(ChangePwdModel model) { if (!ValidateModel(model)) return View(model); LoginBl.OnChangePwd(model); if (!string.IsNullOrEmpty(model.Error)) ModelState.AddModelError("", model.Error); else model.Success = "Пароль успешно изменен."; return View(model); }
public void OnChangePwd(ChangePwdModel model) { try { User user = UserDao.Load(CurrentUser.Id); user.Password = model.NewPassword; UserDao.MergeAndFlush(user); } catch (Exception ex) { Log.Error("Exception:", ex); model.Error = "Исключение:" + ex.GetBaseException().Message; } }