diff options
| author | Luke <luke.pulverenti@gmail.com> | 2017-01-16 01:28:14 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-01-16 01:28:14 -0500 |
| commit | 890d9c60dc1c63008400e716e7741f74b9e93656 (patch) | |
| tree | c2130370a9e414310cb40d1791115a6f82e298f6 /Emby.Server.Implementations/Library/UserManager.cs | |
| parent | abeb40500ca17475fe5f261c8f7c10a0ba7d207b (diff) | |
| parent | 45da5c64b150b0da74b7c265f0ccb5508b25823f (diff) | |
Merge pull request #2400 from MediaBrowser/dev
Dev
Diffstat (limited to 'Emby.Server.Implementations/Library/UserManager.cs')
| -rw-r--r-- | Emby.Server.Implementations/Library/UserManager.cs | 60 |
1 files changed, 47 insertions, 13 deletions
diff --git a/Emby.Server.Implementations/Library/UserManager.cs b/Emby.Server.Implementations/Library/UserManager.cs index 2a5706b3b..eb0d0cf9b 100644 --- a/Emby.Server.Implementations/Library/UserManager.cs +++ b/Emby.Server.Implementations/Library/UserManager.cs @@ -236,29 +236,63 @@ namespace Emby.Server.Implementations.Library var user = Users .FirstOrDefault(i => string.Equals(username, i.Name, StringComparison.OrdinalIgnoreCase)); - if (user == null) - { - throw new SecurityException("Invalid username or password entered."); - } + var success = false; - if (user.Policy.IsDisabled) + if (user != null) { - throw new SecurityException(string.Format("The {0} account is currently disabled. Please consult with your administrator.", user.Name)); - } + // Authenticate using local credentials if not a guest + if (!user.ConnectLinkType.HasValue || user.ConnectLinkType.Value != UserLinkType.Guest) + { + success = string.Equals(GetPasswordHash(user), passwordSha1.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase); - var success = false; + if (!success && _networkManager.IsInLocalNetwork(remoteEndPoint) && user.Configuration.EnableLocalPassword) + { + success = string.Equals(GetLocalPasswordHash(user), passwordSha1.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase); + } + } - // Authenticate using local credentials if not a guest - if (!user.ConnectLinkType.HasValue || user.ConnectLinkType.Value != UserLinkType.Guest) + // Maybe user accidently entered connect credentials. let's be flexible + if (!success && user.ConnectLinkType.HasValue && !string.IsNullOrWhiteSpace(passwordMd5) && !string.IsNullOrWhiteSpace(user.ConnectUserName)) + { + try + { + await _connectFactory().Authenticate(user.ConnectUserName, passwordMd5).ConfigureAwait(false); + success = true; + } + catch + { + + } + } + } + + // Try originally entered username + if (!success && (user == null || !string.Equals(user.ConnectUserName, username, StringComparison.OrdinalIgnoreCase))) { - success = string.Equals(GetPasswordHash(user), passwordSha1.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase); + try + { + var connectAuthResult = await _connectFactory().Authenticate(username, passwordMd5).ConfigureAwait(false); - if (!success && _networkManager.IsInLocalNetwork(remoteEndPoint) && user.Configuration.EnableLocalPassword) + user = Users.FirstOrDefault(i => string.Equals(i.ConnectUserId, connectAuthResult.User.Id, StringComparison.OrdinalIgnoreCase)); + + success = user != null; + } + catch { - success = string.Equals(GetLocalPasswordHash(user), passwordSha1.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase); + } } + if (user == null) + { + throw new SecurityException("Invalid username or password entered."); + } + + if (user.Policy.IsDisabled) + { + throw new SecurityException(string.Format("The {0} account is currently disabled. Please consult with your administrator.", user.Name)); + } + // Update LastActivityDate and LastLoginDate, then save if (success) { |
