mirror of
				https://github.com/jellyfin/jellyfin.git
				synced 2025-11-03 19:17:24 -05:00 
			
		
		
		
	handle users logging in locally with Emby Connect
This commit is contained in:
		
							parent
							
								
									6e42398f9e
								
							
						
					
					
						commit
						c47b602499
					
				@ -1122,7 +1122,7 @@ namespace Emby.Server.Implementations.Connect
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public async Task Authenticate(string username, string passwordMd5)
 | 
			
		||||
        public async Task<ConnectAuthenticationResult> Authenticate(string username, string passwordMd5)
 | 
			
		||||
        {
 | 
			
		||||
            if (string.IsNullOrWhiteSpace(username))
 | 
			
		||||
            {
 | 
			
		||||
@ -1151,6 +1151,7 @@ namespace Emby.Server.Implementations.Connect
 | 
			
		||||
            // No need to examine the response
 | 
			
		||||
            using (var response = (await _httpClient.SendAsync(options, "POST").ConfigureAwait(false)).Content)
 | 
			
		||||
            {
 | 
			
		||||
                return _json.DeserializeFromStream<ConnectAuthenticationResult>(response);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -236,6 +236,53 @@ namespace Emby.Server.Implementations.Library
 | 
			
		||||
            var user = Users
 | 
			
		||||
                .FirstOrDefault(i => string.Equals(username, i.Name, StringComparison.OrdinalIgnoreCase));
 | 
			
		||||
 | 
			
		||||
            var success = false;
 | 
			
		||||
 | 
			
		||||
            if (user != null)
 | 
			
		||||
            {
 | 
			
		||||
                // 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);
 | 
			
		||||
 | 
			
		||||
                    if (!success && _networkManager.IsInLocalNetwork(remoteEndPoint) && user.Configuration.EnableLocalPassword)
 | 
			
		||||
                    {
 | 
			
		||||
                        success = string.Equals(GetLocalPasswordHash(user), passwordSha1.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // 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)))
 | 
			
		||||
            {
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    var connectAuthResult = await _connectFactory().Authenticate(username, passwordMd5).ConfigureAwait(false);
 | 
			
		||||
 | 
			
		||||
                    user = Users.FirstOrDefault(i => string.Equals(i.ConnectUserId, connectAuthResult.User.Id, StringComparison.OrdinalIgnoreCase));
 | 
			
		||||
 | 
			
		||||
                    success = user != null;
 | 
			
		||||
                }
 | 
			
		||||
                catch
 | 
			
		||||
                {
 | 
			
		||||
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (user == null)
 | 
			
		||||
            {
 | 
			
		||||
                throw new SecurityException("Invalid username or password entered.");
 | 
			
		||||
@ -246,19 +293,6 @@ namespace Emby.Server.Implementations.Library
 | 
			
		||||
                throw new SecurityException(string.Format("The {0} account is currently disabled. Please consult with your administrator.", user.Name));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var success = false;
 | 
			
		||||
 | 
			
		||||
            // 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);
 | 
			
		||||
 | 
			
		||||
                if (!success && _networkManager.IsInLocalNetwork(remoteEndPoint) && user.Configuration.EnableLocalPassword)
 | 
			
		||||
                {
 | 
			
		||||
                    success = string.Equals(GetLocalPasswordHash(user), passwordSha1.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Update LastActivityDate and LastLoginDate, then save
 | 
			
		||||
            if (success)
 | 
			
		||||
            {
 | 
			
		||||
 | 
			
		||||
@ -61,7 +61,7 @@ namespace MediaBrowser.Controller.Connect
 | 
			
		||||
        /// <param name="username">The username.</param>
 | 
			
		||||
        /// <param name="passwordMd5">The password MD5.</param>
 | 
			
		||||
        /// <returns>Task.</returns>
 | 
			
		||||
        Task Authenticate(string username, string passwordMd5);
 | 
			
		||||
        Task<ConnectAuthenticationResult> Authenticate(string username, string passwordMd5);
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the local user.
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user