예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="username"></param>
        /// <param name="passwordHash"></param>
        /// <returns></returns>
        public AccountDto Verify(string username, string passwordHash)
        {
            using (var connection = GetConnection())
            {
                connection.Open();

                var command = @"
SELECT TOP 1 a.*
FROM [_Accounts] a
    INNER JOIN [_TenantAccounts] ta on a.Id=ta.AccountId
    INNER JOIN [_Tenants] t on t.Id=ta.TenantId
WHERE a.IsValid=1 AND t.IsValid=1 AND ta.IsValid=1 AND @username=a.Username";

                var account = connection.QueryFirstOrDefault <AccountDto>(command, new { username });

                if (account == null)
                {
                    return(null);
                }

                var verifyResult = _passwordHasher.VerifyHashedPassword(account.PwdHash, passwordHash);

                if (!verifyResult)
                {
                    return(null);
                }

                return(account);
            }
        }
예제 #2
0
        public PortalLoginDto VerifyPortalLogin(string username, string password)
        {
            using (var connection = GetConnection())
            {
                connection.Open();

                var command = @"
SELECT u.*
FROM [PortalLogins] u
WHERE u.IsValid=1 AND u.Username = @Username";

                var login = connection.Query <PortalLogin>(command, new { Username = username }).FirstOrDefault();

                if (login == null)
                {
                    return(null);
                }

                var verifyResult = _passwordHasher.VerifyHashedPassword(login.PasswordHash, password);

                if (!verifyResult)
                {
                    return(null);
                }

                var dto = new PortalLoginDto()
                {
                    Id                 = login.Id,
                    Username           = login.Username,
                    IsPasswordToChange = login.IsPasswordToChange,
                    IsLocked           = login.IsLocked,
                    CreatorId          = login.CreatorId,
                    EditorId           = login.EditorId,
                    CreationTime       = login.CreationTime,
                    LastEditTime       = login.LastEditTime,
                    IsValid            = login.IsValid
                };

                return(dto);
            }
        }