private async Task IncrementAccessFailedCount(TUser user)
    {
        var accessFailedCount = await _userLockoutStore.IncrementAccessFailedCountAsync(user);

        var shouldLockoutUser = accessFailedCount > MaxFailedAccessAttemptsBeforeLockout;

        if (shouldLockoutUser)
        {
            await _userLockoutStore.SetLockoutEnabledAsync(user, true);

            var lockoutEndDate = new DateTimeOffset(DateTime.Now + DefaultAccountLockoutTimeSpan);

            await _userLockoutStore.SetLockoutEndDateAsync(user, lockoutEndDate);
        }
    }
Ejemplo n.º 2
0
        public override async Task <IdentityResult> AccessFailedAsync(int userId)
        {
            IidUser user = await FindByIdAsync(userId);

            if (user == null)
            {
                throw new InvalidOperationException(("UserId not found: " + userId.ToString()));
            }

            int accessFailedCount = await _userLockoutStore.IncrementAccessFailedCountAsync(user);

            if (accessFailedCount == Settings.MaxFailedAccessAttemptsBeforePasswordReset)
            {
                // Send the user an email with a link to reset the password.
                await SendForgotPasswordLinkEmail(user);
            }
            else if (accessFailedCount >= MaxFailedAccessAttemptsBeforeLockout)
            {
                // Lock the user out.
                await _userLockoutStore.SetLockoutEndDateAsync(user, DateTimeOffset.UtcNow.Add(DefaultAccountLockoutTimeSpan));
            }

            return(await UpdateAsync(user));
        }