diff --git a/src/Services/LdapService.cs b/src/Services/LdapService.cs index 736ef8e..47b2506 100644 --- a/src/Services/LdapService.cs +++ b/src/Services/LdapService.cs @@ -144,16 +144,23 @@ public partial class LdapService : IDisposable await ConnectAndBind(); try { - UserModel user = await GetUserByUidAsync(username); - if (user.UserPassword is null) + try + { + UserModel user = await GetUserByUidAsync(username); + if (user.UserPassword is null) + { + return new() { Success = false, AuthenticationState = UserNotAuthenticatedReason.InvalidCredentials }; + } + if (CompareStringToSha256(password, user.UserPassword)) + { + return new() { Success = true }; + } + return new() { Success = false, AuthenticationState = UserNotAuthenticatedReason.InvalidCredentials }; + } + catch (InvalidOperationException) { return new() { Success = false, AuthenticationState = UserNotAuthenticatedReason.InvalidCredentials }; } - if (CompareStringToSha256(password, user.UserPassword)) - { - return new() { Success = true}; - } - return new() { Success = false, AuthenticationState = UserNotAuthenticatedReason.InvalidCredentials }; } catch (LdapException) {