Browse Source

Handle the case when the stored password is null, but the user tried to login with a password.

aled 5 years ago
parent
commit
c722ad22ec
1 changed files with 19 additions and 15 deletions
  1. 19 15
      Emby.Server.Implementations/Library/DefaultAuthenticationProvider.cs

+ 19 - 15
Emby.Server.Implementations/Library/DefaultAuthenticationProvider.cs

@@ -61,25 +61,29 @@ namespace Emby.Server.Implementations.Library
                 });
             }
 
-            byte[] passwordbytes = Encoding.UTF8.GetBytes(password);
-
-            PasswordHash readyHash = PasswordHash.Parse(resolvedUser.Password);
-            if (_cryptographyProvider.GetSupportedHashMethods().Contains(readyHash.Id)
-                || _cryptographyProvider.DefaultHashMethod == readyHash.Id)
+            // Handle the case when the stored password is null, but the user tried to login with a password
+            if (resolvedUser.Password != null)
             {
-                byte[] calculatedHash = _cryptographyProvider.ComputeHash(
-                    readyHash.Id,
-                    passwordbytes,
-                    readyHash.Salt.ToArray());
+                byte[] passwordbytes = Encoding.UTF8.GetBytes(password);
 
-                if (readyHash.Hash.SequenceEqual(calculatedHash))
+                PasswordHash readyHash = PasswordHash.Parse(resolvedUser.Password);
+                if (_cryptographyProvider.GetSupportedHashMethods().Contains(readyHash.Id)
+                    || _cryptographyProvider.DefaultHashMethod == readyHash.Id)
                 {
-                    success = true;
+                    byte[] calculatedHash = _cryptographyProvider.ComputeHash(
+                        readyHash.Id,
+                        passwordbytes,
+                        readyHash.Salt.ToArray());
+
+                    if (readyHash.Hash.SequenceEqual(calculatedHash))
+                    {
+                        success = true;
+                    }
+                }
+                else
+                {
+                    throw new AuthenticationException($"Requested crypto method not available in provider: {readyHash.Id}");
                 }
-            }
-            else
-            {
-                throw new AuthenticationException($"Requested crypto method not available in provider: {readyHash.Id}");
             }
 
             if (!success)