本文介绍了UserManager.FindAsync(用户名,密码)在ASP.NET 5/Identity 3中不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将项目升级到ASP.NET 5/MVC 6.

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

AspNet.Identity附带的UserManager曾经有一个FindAsync方法,可以在其中输入用户名和密码.似乎不再存在了.

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.

使用JWT承载身份验证时,我认为我不需要SigninManager或身份验证.我只需要在授予访问令牌之前检查用户名和密码是否有效,

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,

推荐答案

只需使用 UserManager.FindByNameAsync()查找用户对象,然后检查其密码:

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
}

这篇关于UserManager.FindAsync(用户名,密码)在ASP.NET 5/Identity 3中不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 03:04