private async Task <ClaimsIdentity> GetRegistrationIdentity(string userName, string password) { if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password)) { return(await Task.FromResult <ClaimsIdentity>(null)); } // get the user to verifty var userToVerify = await _userManager.FindByNameAsync(userName); if (userToVerify == null) { return(await Task.FromResult <ClaimsIdentity>(null)); } var looked = await _userManager.IsLockedOutAsync(userToVerify); if (looked) { ModelState.AddModelError("login_failure", $"Number of your login attempts expired, try again in {userToVerify.LockoutEnd}"); return(await Task.FromResult <ClaimsIdentity>(null)); } // check the credentials if (await _userManager.CheckPasswordAsync(userToVerify, password)) { await _userManager.ResetAccessFailedCountAsync(userToVerify); return(await Task.FromResult(await _jwtFactory.GenerateClaimsIdentityForRegistration(userName, userToVerify.Id))); } //inc the number of failed logins await _userManager.AccessFailedAsync(userToVerify); // Credentials are invalid, or account doesn't exist return(await Task.FromResult <ClaimsIdentity>(null)); }