C# PasswordSignInAsync始终返回“;用户的密码无效";身份
我的控制器中有以下代码C# PasswordSignInAsync始终返回“;用户的密码无效";身份,c#,asp.net-core,asp.net-identity,.net-5,C#,Asp.net Core,Asp.net Identity,.net 5,我的控制器中有以下代码 private readonly SignInManager<RegisteredUser> _signInManager; ... SignInResult signInResult = await _signInManager.PasswordSignInAsync(loginViewModel.UserName, loginViewModel.Password, true, false); 但是PasswordSignInAsync总是返回
private readonly SignInManager<RegisteredUser> _signInManager;
...
SignInResult signInResult = await _signInManager.PasswordSignInAsync(loginViewModel.UserName, loginViewModel.Password, true, false);
但是PasswordSignInAsync
总是返回SignInResult.Failed
,但我非常确定用户名/密码是正确的,因为如果我手动对密码进行哈希运算并与DB进行比较,就可以了
当我检查日志时,记录如下:
"data": {
"baseType": "MessageData",
"baseData": {
"ver": 2,
"message": "Invalid password for user.",
"severityLevel": "Warning",
"properties": {
"DeveloperMode": "true",
"CategoryName": "Microsoft.AspNetCore.Identity.UserManager",
"SpanId": "14a4a0e99c59094d",
"ActionName": "CityLibrary.Web.Api.ApiControllers.AuthController.Login",
"RequestPath": "/api/auth/login",
"AspNetCoreEnvironment": "Development",
"RequestId": "0HM8K6NUPB6NK",
"ParentId": "0000000000000000",
"ActionId": "2c5ca137-ddc1-4b75-b23d-38e7eecaa2ea",
"OriginalFormat": "Invalid password for user."
}
}
}
这里有我遗漏的步骤吗?我的猜测是,在对密码进行哈希运算或哈希运算两次时,您可能会出错。请分享您的RegisteredUserStore.cs,以及如何实现注册?
public async Task<string> GetPasswordHashAsync(RegisteredUser user, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
return await Task.FromResult(user.PasswordHash);
}
"data": {
"baseType": "MessageData",
"baseData": {
"ver": 2,
"message": "Invalid password for user.",
"severityLevel": "Warning",
"properties": {
"DeveloperMode": "true",
"CategoryName": "Microsoft.AspNetCore.Identity.UserManager",
"SpanId": "14a4a0e99c59094d",
"ActionName": "CityLibrary.Web.Api.ApiControllers.AuthController.Login",
"RequestPath": "/api/auth/login",
"AspNetCoreEnvironment": "Development",
"RequestId": "0HM8K6NUPB6NK",
"ParentId": "0000000000000000",
"ActionId": "2c5ca137-ddc1-4b75-b23d-38e7eecaa2ea",
"OriginalFormat": "Invalid password for user."
}
}
}