public void ModifyPassword(string userName, string oldPassword, string newPassword) { if (string.IsNullOrWhiteSpace(userName)) { throw new Exception("用户名非法。"); } // 新密码是否合法? // 旧密码是否正确? var theUser = this.GetUser(userName); if (theUser == null) { throw new Exception("用户不存在。"); } var oldPwdMd5 = HelperTool.BuildMd5(oldPassword); if (!HelperTool.BytesEquals(oldPwdMd5, theUser.Password)) { throw new Exception("旧密码不正确。"); } // 更新密码。 var newPwdMd5 = HelperTool.BuildMd5(newPassword); GlobalServices.Repository.Update <User>(new { Password = newPwdMd5 }, p => p.Code == theUser.Code); }
public void LogOn(string userName, byte[] pwdActual) { if (string.Equals(userName, _currentUser.Name, StringComparison.OrdinalIgnoreCase)) { throw new Exception("用户名相同,无需切换。"); } // var theUser = _userMgr.GetUser(userName); if (theUser == null) { throw new Exception("指定的用户不存在。"); } if (!HelperTool.BytesEquals(theUser.Password, pwdActual)) { throw new Exception("密码不正确。"); } // 发布用户将要切换事件。 GlobalMessageBus.PublishUserChanging(new EventArgs()); // 更新用户。 _currentUser.Id = theUser.Code; _currentUser.Name = theUser.Name; if (theUser.Privileges != null) { _currentUser.Privileges = theUser.Privileges.ToList(); } else { _currentUser.Privileges.Clear(); } // 发布用户切换事件。 GlobalMessageBus.PublishUserChanged(new EventArgs()); }