aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server.Implementations/Users/DefaultAuthenticationProvider.cs
diff options
context:
space:
mode:
authorBond_009 <bond.009@outlook.com>2023-08-21 19:09:32 +0200
committerBond_009 <bond.009@outlook.com>2023-08-21 19:09:32 +0200
commita963bce9beb16f0d66ec0cef8d92f0d4f6536730 (patch)
tree4cf79d2edaee5663a8a0f2f91e36d9f63f071798 /Jellyfin.Server.Implementations/Users/DefaultAuthenticationProvider.cs
parent388420faa21eee90474e6c6723085f6df5192972 (diff)
Reduce log spam on failed logins
Failed logins already get logged higher up the call chain
Diffstat (limited to 'Jellyfin.Server.Implementations/Users/DefaultAuthenticationProvider.cs')
-rw-r--r--Jellyfin.Server.Implementations/Users/DefaultAuthenticationProvider.cs21
1 files changed, 12 insertions, 9 deletions
diff --git a/Jellyfin.Server.Implementations/Users/DefaultAuthenticationProvider.cs b/Jellyfin.Server.Implementations/Users/DefaultAuthenticationProvider.cs
index 72f3d6e8e..cb2d09a67 100644
--- a/Jellyfin.Server.Implementations/Users/DefaultAuthenticationProvider.cs
+++ b/Jellyfin.Server.Implementations/Users/DefaultAuthenticationProvider.cs
@@ -1,4 +1,5 @@
using System;
+using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Jellyfin.Data.Entities;
using MediaBrowser.Controller.Authentication;
@@ -39,14 +40,18 @@ namespace Jellyfin.Server.Implementations.Users
/// <inheritdoc />
// This is the version that we need to use for local users. Because reasons.
- public Task<ProviderAuthenticationResult> Authenticate(string username, string password, User resolvedUser)
+ public Task<ProviderAuthenticationResult> Authenticate(string username, string password, User? resolvedUser)
{
- if (resolvedUser is null)
+ [DoesNotReturn]
+ static void ThrowAuthenticationException()
{
- throw new AuthenticationException("Specified user does not exist.");
+ throw new AuthenticationException("Invalid username or password");
}
- bool success = false;
+ if (resolvedUser is null)
+ {
+ ThrowAuthenticationException();
+ }
// As long as jellyfin supports password-less users, we need this little block here to accommodate
if (!HasPassword(resolvedUser) && string.IsNullOrEmpty(password))
@@ -60,15 +65,13 @@ namespace Jellyfin.Server.Implementations.Users
// Handle the case when the stored password is null, but the user tried to login with a password
if (resolvedUser.Password is null)
{
- throw new AuthenticationException("Invalid username or password");
+ ThrowAuthenticationException();
}
PasswordHash readyHash = PasswordHash.Parse(resolvedUser.Password);
- success = _cryptographyProvider.Verify(readyHash, password);
-
- if (!success)
+ if (!_cryptographyProvider.Verify(readyHash, password))
{
- throw new AuthenticationException("Invalid username or password");
+ ThrowAuthenticationException();
}
// Migrate old hashes to the new default