Fixed uncaught exception when user not found

This commit is contained in:
2025-10-03 16:40:16 +02:00
parent 0bb5f650b6
commit a5a08e5876

View File

@@ -142,6 +142,8 @@ public partial class LdapService : IDisposable
public async Task<UserAuthenticationResult> AuthenticateUser(string username, string password) public async Task<UserAuthenticationResult> AuthenticateUser(string username, string password)
{ {
await ConnectAndBind(); await ConnectAndBind();
try
{
try try
{ {
UserModel user = await GetUserByUidAsync(username); UserModel user = await GetUserByUidAsync(username);
@@ -151,10 +153,15 @@ public partial class LdapService : IDisposable
} }
if (CompareStringToSha256(password, user.UserPassword)) if (CompareStringToSha256(password, user.UserPassword))
{ {
return new() { Success = true}; return new() { Success = true };
} }
return new() { Success = false, AuthenticationState = UserNotAuthenticatedReason.InvalidCredentials }; return new() { Success = false, AuthenticationState = UserNotAuthenticatedReason.InvalidCredentials };
} }
catch (InvalidOperationException)
{
return new() { Success = false, AuthenticationState = UserNotAuthenticatedReason.InvalidCredentials };
}
}
catch (LdapException) catch (LdapException)
{ {
return new() { Success = false, AuthenticationState = UserNotAuthenticatedReason.InvalidCredentials }; return new() { Success = false, AuthenticationState = UserNotAuthenticatedReason.InvalidCredentials };