From 19470f6228e6c9e59a04b5e5ca7edd4b162921b2 Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 7 Feb 2025 16:32:10 +0800 Subject: [PATCH] Check user password if sign in result is `IsNotAllowed`. --- .../Controllers/TokenController.Password.cs | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs index 392e696d08..33a1a37845 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs @@ -115,24 +115,32 @@ public partial class TokenController } else if (result.IsNotAllowed) { - Logger.LogInformation("Authentication failed for username: {username}, reason: not allowed", request.Username); - - if (user.ShouldChangePasswordOnNextLogin) + if (!await UserManager.CheckPasswordAsync(user, request.Password)) { - return await HandleShouldChangePasswordOnNextLoginAsync(request, user, request.Password); + Logger.LogInformation("Authentication failed for username: {username}, reason: invalid credentials", request.Username); + errorDescription = "Invalid username or password!"; } - - if (await UserManager.ShouldPeriodicallyChangePasswordAsync(user)) + else { - return await HandlePeriodicallyChangePasswordAsync(request, user, request.Password); - } + Logger.LogInformation("Authentication failed for username: {username}, reason: not allowed", request.Username); - if (user.IsActive) - { - return await HandleConfirmUserAsync(request, user); - } + if (user.ShouldChangePasswordOnNextLogin) + { + return await HandleShouldChangePasswordOnNextLoginAsync(request, user, request.Password); + } - errorDescription = "You are not allowed to login! Your account is inactive."; + if (await UserManager.ShouldPeriodicallyChangePasswordAsync(user)) + { + return await HandlePeriodicallyChangePasswordAsync(request, user, request.Password); + } + + if (user.IsActive) + { + return await HandleConfirmUserAsync(request, user); + } + + errorDescription = "You are not allowed to login! Your account is inactive."; + } } else {