public ActionResult ModifyPwd(ModifyPwdModel model) { //加密 model.NewPwd = model.NewPwdConfirm = Utility.EncryptHelper.MD5Encrypt(model.NewPwd); //model.OldPwd = Utility.EncryptHelper.MD5Encrypt(model.OldPwd); //取得当前用户 var sessionUser = Session["user"] as User; using (TCTEContext db = new TCTEContext()) { int userId = int.Parse(Request.QueryString["userId"]); var user = db.Users.Where(u => u.Id == userId).SingleOrDefault(); //校验原密码 if (!RoleHelper.IsInRole(SystemRole.SUPER_ADMIN)) { if (user.Password != model.OldPwd) { ModelState.AddModelError("", "原密码不正确"); return View(); } } //修改密码 user.Password = model.NewPwdConfirm; db.SaveChanges(); return Redirect("/User/index"); } }
public ActionResult ModifyPwd( ModifyPwdModel model ) { if ( ModelState.IsValid ) { //加密 model.NewPwd = model.NewPwdConfirm = Utility.EncryptHelper.MD5Encrypt( model.NewPwd ); model.OldPwd = Utility.EncryptHelper.MD5Encrypt( model.OldPwd ); //取得当前用户 var sessionUser = Session[ "user" ] as User; using ( TCTEContext db = new TCTEContext( ) ) { var user = db.Users.Find( sessionUser.Id ); //校验原密码 if ( user.Password != model.OldPwd ) { ModelState.AddModelError( "", "原密码不正确" ); return View( ); } //修改密码 user.Password = model.NewPwdConfirm; db.SaveChanges( ); return RedirectToAction( "LogOut" ); } } return View( ); }