Exemplo n.º 1
0
        public Account AuthenticateAccount(string email, string password, string hashedPassword, string remoteEndPoint, bool isUserSession)
        {
            if (string.IsNullOrWhiteSpace(email))
            {
                throw new ArgumentNullException("email");
            }

            if (hashedPassword == null)
            {
                hashedPassword = _defaultAuthenticationProvider.GetHashedString(password);
            }

            var account = Accounts
                          .FirstOrDefault(i => string.Equals(email, i.Email, StringComparison.OrdinalIgnoreCase) && string.Equals(hashedPassword, i.Password));

            if (account == null)
            {
                throw new SecurityException("Email ou senha inválida.");
            }

            if (!account.Enabled)
            {
                throw new SecurityException("Esta conta está desabilitada, consulte o Administrador.");
            }

            if (account.ExpDate != null && DateTime.Compare(account.ExpDate.GetValueOrDefault(), DateTime.Now) < 0)
            {
                throw new SecurityException("Esta conta está expirada, entre em contato com o revendedor para renovar seu plano.");
            }

            return(account);
        }
Exemplo n.º 2
0
        private async Task <Tuple <IAuthenticationProvider, string, bool> > AuthenticateLocalUser(string username, string password, string hashedPassword, User user, string remoteEndPoint)
        {
            string updatedUsername = null;
            bool   success         = false;
            IAuthenticationProvider authenticationProvider = null;

            if (password != null && user != null)
            {
                // Doesn't look like this is even possible to be used, because of password == null checks below
                hashedPassword = _defaultAuthenticationProvider.GetHashedString(user, password);
            }

            if (password == null)
            {
                // legacy
                success = string.Equals(_defaultAuthenticationProvider.GetPasswordHash(user), hashedPassword.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase);
            }
            else
            {
                foreach (var provider in GetAuthenticationProviders(user))
                {
                    var providerAuthResult = await AuthenticateWithProvider(provider, username, password, user).ConfigureAwait(false);

                    updatedUsername = providerAuthResult.Item1;
                    success         = providerAuthResult.Item2;

                    if (success)
                    {
                        authenticationProvider = provider;
                        username = updatedUsername;
                        break;
                    }
                }
            }

            if (user != null)
            {
                if (!success && _networkManager.IsInLocalNetwork(remoteEndPoint) && user.Configuration.EnableLocalPassword)
                {
                    if (password == null)
                    {
                        // legacy
                        success = string.Equals(GetLocalPasswordHash(user), hashedPassword.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase);
                    }
                    else
                    {
                        success = string.Equals(GetLocalPasswordHash(user), _defaultAuthenticationProvider.GetHashedString(user, password), StringComparison.OrdinalIgnoreCase);
                    }
                }
            }

            return(new Tuple <IAuthenticationProvider, string, bool>(authenticationProvider, username, success));
        }
Exemplo n.º 3
0
        private async Task <(IAuthenticationProvider authenticationProvider, string username, bool success)> AuthenticateLocalUser(
            string username,
            string password,
            string hashedPassword,
            User user,
            string remoteEndPoint)
        {
            bool success = false;
            IAuthenticationProvider authenticationProvider = null;

            foreach (var provider in GetAuthenticationProviders(user))
            {
                var providerAuthResult = await AuthenticateWithProvider(provider, username, password, user).ConfigureAwait(false);

                var updatedUsername = providerAuthResult.username;
                success = providerAuthResult.success;

                if (success)
                {
                    authenticationProvider = provider;
                    username = updatedUsername;
                    break;
                }
            }

            if (!success &&
                _networkManager.IsInLocalNetwork(remoteEndPoint) &&
                user.Configuration.EnableLocalPassword)
            {
                success = string.Equals(
                    GetLocalPasswordHash(user),
                    _defaultAuthenticationProvider.GetHashedString(user, password),
                    StringComparison.OrdinalIgnoreCase);
            }

            return(authenticationProvider, username, success);
        }