Beispiel #1
0
        private async Task <UserInfo> AuthenticateUserAsync(string userName, string password)
        {
            // Find in catalog (not found error)
            var ui = await _userManager.GetUserInfoAsync(userName);

            if (ui == null)
            {
                throw new AuthenticationException($"Login for name '{userName}' not registered in system catalog");
            }

            string impersonateType = ui.Identity.AuthenticationType;

            if (impersonateType.Equals("windows", StringComparison.OrdinalIgnoreCase))
            {
                try
                {
                    Impersonator.Execute <bool>(userName, password, () => true);
                }
                catch (Exception ex)
                {
                    throw new AuthenticationException($"Authentication failed for user '{userName}'", ex);
                }
            }
            else             //basic
            {
                if (!ui.PasswordHash.Equals(CryptoHelper.ComputeSha256Hash(password), StringComparison.Ordinal))
                {
                    throw new AuthenticationException($"Bad password for user '{userName}'");
                }
            }
            return(ui);
        }
Beispiel #2
0
 private void ImpersonateTest()
 {
     Impersonator.Execute <bool>("Test", "@TestPassword", () => true);
 }