added justaman notes, fixed new bug from emty has removals

This commit is contained in:
Phallacy
2019-02-18 01:26:01 -08:00
parent 9f3aa2cead
commit 48e7274d37
4 changed files with 59 additions and 34 deletions

View File

@@ -37,7 +37,17 @@ namespace Emby.Server.Implementations.Library
if (resolvedUser == null)
{
throw new Exception("Invalid username or password");
}
}
//As long as jellyfin supports passwordless users, we need this little block here to accomodate
if (IsPasswordEmpty(resolvedUser, password))
{
return Task.FromResult(new ProviderAuthenticationResult
{
Username = username
});
}
ConvertPasswordFormat(resolvedUser);
byte[] passwordbytes = Encoding.UTF8.GetBytes(password);
@@ -106,15 +116,30 @@ namespace Emby.Server.Implementations.Library
return Task.FromResult(hasConfiguredPassword);
}
private bool IsPasswordEmpty(User user, string passwordHash)
{
return string.IsNullOrEmpty(passwordHash);
private bool IsPasswordEmpty(User user, string password)
{
if (string.IsNullOrEmpty(user.Password))
{
return string.IsNullOrEmpty(password);
}
return false;
}
public Task ChangePassword(User user, string newPassword)
{
//string newPasswordHash = null;
ConvertPasswordFormat(user);
ConvertPasswordFormat(user);
//This is needed to support changing a no password user to a password user
if (string.IsNullOrEmpty(user.Password))
{
PasswordHash newPasswordHash = new PasswordHash(_cryptographyProvider);
newPasswordHash.SaltBytes = _cryptographyProvider.GenerateSalt();
newPasswordHash.Salt = PasswordHash.ConvertToByteString(newPasswordHash.SaltBytes);
newPasswordHash.Id = _cryptographyProvider.DefaultHashMethod;
newPasswordHash.Hash = GetHashedStringChangeAuth(newPassword, newPasswordHash);
user.Password = newPasswordHash.ToString();
return Task.CompletedTask;
}
PasswordHash passwordHash = new PasswordHash(user.Password);
if (passwordHash.Id == "SHA1" && string.IsNullOrEmpty(passwordHash.Salt))
{
@@ -143,11 +168,6 @@ namespace Emby.Server.Implementations.Library
return user.Password;
}
public string GetEmptyHashedString(User user)
{
return null;
}
public string GetHashedStringChangeAuth(string newPassword, PasswordHash passwordHash)
{
passwordHash.HashBytes = Encoding.UTF8.GetBytes(newPassword);