public async Task <SignInResult> SignInAsync(string userName, string password) { var maybe = await FindUserByNameAsync(userName); if (!maybe.HasValue) { return(SignInResult.Fail(_localizer["SignIn.Messages.Failure"])); } var user = maybe.Value; if (_password.VerifyHashedPassword(user.PasswordHash, password) == PasswordVerificationResult.Failed) { return(SignInResult.Fail(_localizer["SignIn.Messages.Failure"])); } if (!user.IsActive) { return(SignInResult.Fail(_localizer["SignIn.Messages.IsNotActive"])); } var userId = user.Id; var claims = await BuildClaimsAsync(userId); var token = await _token.BuildTokenAsync(userId, claims); _antiforgery.AddTokenToResponse(claims); return(SignInResult.Ok(token)); }
public async Task <SignInResult> SignInAsync(string userName, string password) { var userMaybe = await _userManager.FindByNameAsync(userName); if (!userMaybe.HasValue) { return(SignInResult.Failed(_localizer["SignIn.Messages.Failure"])); } var user = userMaybe.Value; if (!_userManager.VerifyHashedPassword(user.PasswordHash, password)) { return(SignInResult.Failed(_localizer["SignIn.Messages.Failure"])); } if (!user.IsActive) { return(SignInResult.Failed(_localizer["SignIn.Messages.IsNotActive"])); } var userId = user.Id; var claims = await GenerateClaimsAsync(userId); var token = await _tokenManager.BuildTokenAsync(userId, claims); _antiForgery.RegenerateAntiForgeryCookies(claims); return(SignInResult.Success(token)); }