问题
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