public ActionResult ChangePassword(ChangePasswordModel model) { string currentPerson = GetCurrentPerson(); ViewBag.PersonNamea = currentPerson; if (string.IsNullOrWhiteSpace(currentPerson)) { ModelState.AddModelError("", "对不起,请重新登陆"); return(View()); } if (ModelState.IsValid) { IAccountBLL accountBLL = new AccountBLL(); if (null != (accountBLL.ValidateUser(currentPerson, EncryptAndDecrypte.EncryptString(model.OldPassword)))) { if (accountBLL.ChangePassword(currentPerson, model.OldPassword, model.NewPassword)) { ModelState.AddModelError("", "修改密码成功"); return(View()); } } } ModelState.AddModelError("", "修改密码不成功,请核实数据"); return(View()); }
public ActionResult ChangePassword(ChangePasswordViewModel passwordVm) { ViewBag.Message = accountBll.ChangePassword(passwordVm); return(View()); }
protected void buttonChangePassword_ServerClick(object sender, EventArgs e) { AccountBLL accountBLL = new AccountBLL(); string passwordCurrent = inputPasswordCurrent.Value; string passwordNew = inputPasswordNew.Value; string passwordNewRepeat = inputPasswordNewRepeat.Value; #region Validation bool[] validate = Enumerable.Repeat(true, 2).ToArray(); // If any fields are empty if (string.IsNullOrEmpty(passwordCurrent) || accountBLL.GetStatus(AccountBLL.GetNRIC(), passwordCurrent).status == 0) { validate[0] = false; inputPasswordCurrent.Attributes.Add("class", "form-control form-control-sm is-invalid"); } else { inputPasswordCurrent.Attributes.Add("class", "form-control form-control-sm is-valid"); } if (string.IsNullOrEmpty(passwordNew) || string.IsNullOrEmpty(passwordNewRepeat) || !AccountBLL.IsPasswordValid(passwordNew, passwordNewRepeat) || passwordCurrent.Equals(passwordNew)) { validate[1] = false; inputPasswordNew.Attributes.Add("class", "form-control form-control-sm is-invalid"); inputPasswordNewRepeat.Attributes.Add("class", "form-control form-control-sm is-invalid"); } else { inputPasswordNew.Attributes.Add("class", "form-control form-control-sm is-valid"); inputPasswordNewRepeat.Attributes.Add("class", "form-control form-control-sm is-valid"); } if (!validate[0]) { labelMessage.Text = "Current Password is incorrect."; } else if (!validate[1]) { labelMessage.Text = "New password is invalid."; } #endregion if (validate.Contains(false)) { spanMessage.Visible = true; } else { try { accountBLL.ChangePassword(passwordNew); spanMessage.Visible = false; ScriptManager.RegisterStartupScript(this, GetType(), "update password success", "toastr['success']('Password were successfully Updated');$('#modelSuccess').modal('show');", true); } catch { inputPasswordCurrent.Attributes.Add("class", "form-control form-control-sm"); inputPasswordNew.Attributes.Add("class", "form-control form-control-sm"); inputPasswordNewRepeat.Attributes.Add("class", "form-control form-control-sm"); ScriptManager.RegisterStartupScript(this, GetType(), "update password error", "toastr['error']('Error occured when Updating Password');", true); } } }