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

@@ -144,16 +144,23 @@ public partial class LdapService : IDisposable
await ConnectAndBind(); await ConnectAndBind();
try try
{ {
UserModel user = await GetUserByUidAsync(username); try
if (user.UserPassword is null) {
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 }; 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) catch (LdapException)
{ {