/// <summary> /// 修改當前登陸用戶密碼 /// </summary> /// <returns></returns> [AbpAuthorize] public async Task ChangePassword(ChangePasswordInput input) { input.OldPassword = input.OldPassword.Trim(); input.NewPassword = input.NewPassword.Trim(); //判斷舊密碼是否正確 if (string.IsNullOrWhiteSpace(input.OldPassword) || string.IsNullOrWhiteSpace(input.NewPassword)) { throw new UserFriendlyException("密碼不能爲空"); } if (input.OldPassword == input.NewPassword) { throw new UserFriendlyException("新舊密碼不能相同"); } //獲取abp用戶 var user = await _userManager.GetUserByIdAsync(AbpSession.UserId.Value); //判斷新密碼是否正確 var result = _passwordHasher.VerifyHashedPassword(user, user.Password, input.OldPassword); if (result == PasswordVerificationResult.Failed) { throw new UserFriendlyException("舊密碼錯誤"); } //新密碼hash var hash = _passwordHasher.HashPassword(user, input.NewPassword); user.Password = hash; await _userManager.UpdateAsync(user); }