UserManager.FindAsync(username, password) not available in ASP.NET 5 / Identity 3

匆匆过客 提交于 2021-02-19 01:16:23

问题


I'm trying to upgrade a project to ASP.NET 5 / MVC 6.

The UserManager that came with AspNet.Identity used to have a FindAsync method where I could pass in a username and password. It doesn't seem to be there anymore.

I don't think I need the SigninManager or Authentication as I'm using JWT Bearer Authentication. I just need to check the username and password are valid before I grant an access token,


回答1:


Simply use UserManager.FindByNameAsync() to find the user object then check its password:

var user = await _userManager.FindByNameAsync(userName);
if(user!=null && await _userManager.CheckPasswordAsync(user, password))
{
    // user is valid do whatever you want
}



回答2:


It looks like it has been renamed to:

public virtual Task<TUser> FindByNameAsync(string userName)

you can view the source code for UserManager here



来源:https://stackoverflow.com/questions/35041826/usermanager-findasyncusername-password-not-available-in-asp-net-5-identity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!