public async Task TestInitialize()
        {
            await auditor.UnblockAndReset(remoteEndpoint, protocol);

            DateTime?TP = await auditor.GetEarliestLoginOpportunity(remoteEndpoint, protocol);

            Assert.IsNull(TP);
        }
Beispiel #2
0
        /// <summary>
        /// Attempts to login in the system.
        /// </summary>
        /// <param name="UserName">User name</param>
        /// <param name="Password">Password</param>
        /// <param name="RemoteEndPoint">Remote endpoint of user attempting to login.</param>
        /// <param name="Protocol">Protocol used for login.</param>
        /// <returns>Login result.</returns>
        public static async Task <LoginResult> Login(string UserName, string Password, string RemoteEndPoint, string Protocol)
        {
            if (string.IsNullOrEmpty(Password))
            {
                return(new LoginResult());
            }

            if (!(loginAuditor is null))
            {
                DateTime?Next = await loginAuditor.GetEarliestLoginOpportunity(RemoteEndPoint, Protocol);

                if (Next.HasValue)
                {
                    return(new LoginResult(Next.Value));
                }
            }

            User User = await GetUser(UserName, false);

            if (!(User is null) && User.PasswordHash != Convert.ToBase64String(ComputeHash(UserName, Password)))
            {
                User = null;
            }

            if (User is null)
            {
                LoginAuditor.Fail("Invalid login.", UserName, RemoteEndPoint, Protocol);
            }
            else
            {
                LoginAuditor.Success("Successful login.", UserName, RemoteEndPoint, Protocol);
            }

            return(new LoginResult(User));
        }