Example #1
0
        public override async Task AuthenticateLocalAsync(LocalAuthenticationContext ctx)
        {
            var username = ctx.UserName;
            var password = ctx.Password;
            var message  = ctx.SignInMessage;

            ctx.AuthenticateResult = null;

            if (_userStore.SupportsUserPassword)
            {
                var user = await FindUserAsync(username);

                if (user != null)
                {
                    if (_userStore.SupportsUserLockout && await _userStore.IsLockedOutAsync(user.Id))
                    {
                        return;
                    }

                    if (await _userStore.CheckPasswordAsync(user, password))
                    {
                        if (_userStore.SupportsUserLockout)
                        {
                            await _userStore.ResetAccessFailedCountAsync(user.Id);
                        }

                        var result = await PostAuthenticateLocalAsync(user, message);

                        if (result == null)
                        {
                            var claims = await GetClaimsForAuthenticateResult(user);

                            result = new AuthenticateResult(user.Id.ToString(), await GetDisplayNameForAccountAsync(user.Id), claims);
                        }

                        ctx.AuthenticateResult = result;
                    }
                    else if (_userStore.SupportsUserLockout)
                    {
                        await _userStore.AccessFailedAsync(user.Id);
                    }
                }
            }
        }