From a5a08e5876d17058eac91e6229d53789f53458ae Mon Sep 17 00:00:00 2001 From: LD-Reborn Date: Fri, 3 Oct 2025 16:40:16 +0200 Subject: [PATCH] Fixed uncaught exception when user not found --- src/Services/LdapService.cs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) 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) {