ASP.NET 身份登录 [英] ASP.NET Identity login

查看:37
本文介绍了ASP.NET 身份登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 MVC 5 中有一个网站,使用 ASP.NET Identity 登录用户.一切正常.

I have a website in MVC 5 using ASP.NET Identity to login a user. Everything works great.

现在我的合作伙伴需要在他的 WinForms 应用程序中登录一个注册用户.有谁知道 Identity 使用的密码散列算法,或者我如何在 WinForms 应用程序中对用户进行身份验证?

Now my partner needs to login a registered user in his WinForms app. Does anyone know the password hashing algorythm used by Identity or how can I authenticate the user in the WinForms app?

任何提示将不胜感激.

最好的问候.

推荐答案

如果您使用来自 MVC 应用程序的 Microsoft.AspNet.Identity.EntityFramework 并且 WinForm 应用程序可以访问相同的数据库,那么您应该将其配置为使用与 MVC 应用程序相同的 ConnectionString.使用 nuget 将 Microsoft.AspNet.Identity.EntityFramework 添加到 WinForm 应用程序.

If you are using Microsoft.AspNet.Identity.EntityFramework from the MVC app and the WinForm app has access to the same database, then you should configure it to use the same ConnectionString as the MVC application. Add Microsoft.AspNet.Identity.EntityFramework to the WinForm application using nuget.

然后可以使用下面的代码来验证用户名和密码:

Then the following code can be used to verify username and password:

public async Task<bool> VerifyUserNamePassword(string userName, string password)
{
   var usermanager = new UserManager<IdentityUser>(new UserStore<IdentityUser>(new IdentityDbContext()));
   return await usermanager.FindAsync(userName, password) != null;
}

这篇关于ASP.NET 身份登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆