From 212749fa567fa9a1e607c48697d29917d9149fea Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 7 Feb 2025 16:35:06 +0800 Subject: [PATCH] Update IdentityServer `ResourceOwnerPasswordValidator`. --- .../AbpResourceOwnerPasswordValidator.cs | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs index eece31acc3..d4e0fb5490 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs @@ -128,21 +128,29 @@ public class AbpResourceOwnerPasswordValidator : IResourceOwnerPasswordValidator } else if (result.IsNotAllowed) { - Logger.LogInformation("Authentication failed for username: {username}, reason: not allowed", context.UserName); - - if (user.ShouldChangePasswordOnNextLogin) + if (!await UserManager.CheckPasswordAsync(user, context.Password)) { - await HandleShouldChangePasswordOnNextLoginAsync(context, user, context.Password); - return; + Logger.LogInformation("Authentication failed for username: {username}, reason: invalid credentials", context.UserName); + errorDescription = Localizer["InvalidUserNameOrPassword"]; } - - if (await UserManager.ShouldPeriodicallyChangePasswordAsync(user)) + else { - await HandlePeriodicallyChangePasswordAsync(context, user, context.Password); - return; - } + Logger.LogInformation("Authentication failed for username: {username}, reason: not allowed", context.UserName); - errorDescription = Localizer["LoginIsNotAllowed"]; + if (user.ShouldChangePasswordOnNextLogin) + { + await HandleShouldChangePasswordOnNextLoginAsync(context, user, context.Password); + return; + } + + if (await UserManager.ShouldPeriodicallyChangePasswordAsync(user)) + { + await HandlePeriodicallyChangePasswordAsync(context, user, context.Password); + return; + } + + errorDescription = Localizer["LoginIsNotAllowed"]; + } } else {