protected void btnChangePass_Click(object sender, EventArgs e) { if (txtOldPass.Text.Length > 0) { if (txtNewPass.Text.Length > 0 && txtPassword.Text.Length > 0) { if (txtNewPass.Text.Equals(txtPassword.Text)) { string oldPass = FormsAuthentication.HashPasswordForStoringInConfigFile(Security.MD5Encrypt(txtOldPass.Text), "MD5"); UserInfo info = (UserInfo)Session["LoginUser"]; if (oldPass.Equals(info.UserPass)) { string newPass = FormsAuthentication.HashPasswordForStoringInConfigFile(Security.MD5Encrypt(txtPassword.Text), "MD5"); JavaDLL bll = new JavaDLL(); if (bll.changePassword(info.ID, newPass)) { Session.RemoveAll(); RunScript("alert('修改成功!请用新密码登录');top.closePasswordDialog();"); } else { RunScript("alert('修改失败!');"); } } else { RunScript("alert('原密码输入不正确');"); } } else { RunScript("alert('两次输入的密码不一致');"); } } else { RunScript("alert('请输入新密码');"); } } else { RunScript("alert('请输入原密码');"); } }
protected void linPassword_Click(object sender, EventArgs e) { if (txtPassword.Text.Trim().Length > 0) { UserInfo info = (UserInfo)Session["TmpUser"]; info.UserPass = FormsAuthentication.HashPasswordForStoringInConfigFile(Security.MD5Encrypt(txtPassword.Text), "MD5"); JavaDLL dll = new JavaDLL(); if (dll.changePassword(info.ID, info.UserPass)) { labPassword.Visible = true; labPassword.Text = "重置密码成功"; trPass.Visible = false; } else { labPassword.Visible = trPass.Visible = true; labPassword.Text = "重置密码失败"; } } }
public ActionResult ChangePassword(UserInfo user) { user = (UserInfo)Session["LoginUser"]; if (user == null) { return(Redirect("/users/login")); } string psd = FormsAuthentication.HashPasswordForStoringInConfigFile(Security.MD5Encrypt(Request.Form["password"]), "MD5"); if (!psd.Equals(user.UserPass)) { ViewData.Add("PassMsg", "原密码输入不正确"); return(View()); } string newp = Request["newpassword"]; string yzp = Request["newpassword2"]; if (!newp.Equals(yzp)) { ViewData.Add("PassMsg", "两次密码输入不相同"); return(View()); } if (psd.Equals(user.UserPass) && yzp.Length > 0) { user.UserPass = FormsAuthentication.HashPasswordForStoringInConfigFile(Security.MD5Encrypt(yzp), "MD5"); JavaDLL dll = new JavaDLL(); if (dll.changePassword(user.ID, user.UserPass)) { return(RedirectToAction("Setting", "Users", new { er = "psd" })); } else { ViewData.Add("PassMsg", "密码修改失败"); return(View()); } } return(View(user)); }