Asp.net-Mvc

ASP.NET 身份登錄

  • October 20, 2018

我在 MVC 5 中有一個使用 ASP.NET Identity 登錄使用者的網站。一切都很好。

現在我的伙伴需要在他的 WinForms 應用程序中登錄一個註冊使用者。有誰知道 Identity 使用的密碼雜湊算法,或者我如何在 WinForms 應用程序中對使用者進行身份驗證?

任何提示將不勝感激。

最好的祝福。

如果您從 MVC 應用程序使用 Microsoft.AspNet.Identity.EntityFramework 並且 WinForm 應用程序可以訪問相同的數據庫,那麼您應該將其配置為使用與 MVC 應用程序相同的 ConnectionString。使用 nuget 將 Microsoft.AspNet.Identity.EntityFramework 添加到 WinForm 應用程序。

然後可以使用以下程式碼來驗證使用者名和密碼:

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;
}

引用自:https://stackoverflow.com/questions/20952324