【发布时间】:2019-03-13 19:07:41
【问题描述】:
我在 Winforms 项目中使用 AspNet.Identity。我通过传递给 UserManager.FindByNameAsync 的用户名成功找到了用户,但我无法让我的登录名使用传递的密码。我可以使用相同的数据库和完全相同的凭据在我的 MVC 应用程序中正常登录。
这是我的代码:
public async Task<List<string>> VerifyUserNamePassword(string userName, string password)
{
var usermanager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new IdentityFrameworkDbContext()));
var user = await usermanager.FindAsync(userName, password);
//This is ALWAYS NULL!
if (user != null)
label1.Text = "Success!";
var u = await usermanager.FindByEmailAsync(userName);
if (u != null)
{
//This works up to this point - check if password is correct
var success = await usermanager.CheckPasswordAsync(u, password);
//THIS IS ALWAYS FALSE!
if (success)
label1.Text = "YES THIS WORKED!";
}
//This works, I get the Roles back and they are correct
var users = await usermanager.GetRolesAsync(u.Id);
return users.ToList();
}
【问题讨论】:
标签: c# winforms entity-framework asp.net-identity