asp.net-core-mvc - 带有 ASP.NET Core 的谷歌身份验证器

标签 asp.net-core-mvc two-factor-authentication google-authenticator

除了短信和电子邮件之外,是否有任何谷歌身份验证器的示例实现作为两因素身份验证实现?

找到一个样本。 Sample Google Authenticator using asp.net

但是与asp.net core一起使用时有很多变化。

最佳答案

您可以使用AspNetCore.Totp。 https://github.com/damirkusar/AspNetCore.Totp

它的工作原理与 GoogleAuthenticator 完全相同,请查看 Tests 项目的实现(非常简单)。

您只需编写几行即可获取 qurcode 并验证 pin 码:

using AspNetCore.Totp;

...

// To generate the qrcode/setup key

var totpSetupGenerator = new TotpSetupGenerator();
var totpSetup = totpSetupGenerator.Generate("You app name here", "The username", "YourSuperSecretKeyHere", 300, 300);
                                                    
string qrCodeImageUrl = totpSetup.QrCodeImage;
string manualEntrySetupCode = totpSetup.ManualSetupKey;


// To validate the pin after user input (where pin is an int variable)
var totpGenerator = new TotpGenerator();
var totpValidator = new TotpValidator(totpGenerator);
bool isCorrectPIN = totpValidator.Validate("YourSuperSecretKeyHere", pin);

关于asp.net-core-mvc - 带有 ASP.NET Core 的谷歌身份验证器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43956290/

相关文章:

c# - 我可以阻止 MVC Core 中的异步代码吗?

razor - Asp.net Core 如何渲染 View

c# - '无法从程序集加载类型 'Microsoft.AspNetCore.Mvc.MvcJsonOptions' 'Microsoft.AspNetCore.Mvc.Formatters.Json,版本=3.0.0.0

android - 如何在没有谷歌登录的情况下在另一个安卓应用程序中使用谷歌个人资料图片?

c# - 添加Mvc服务后单独添加Mvc选项

perl - Perl 中的 Google 身份验证器实现

python - “用户”对象没有属性 'is_verified'

c# - 两因素谷歌身份验证与服务器上的代码不匹配 - ASP.Net MVC

android - 在非 google android 应用程序中使用 Google Authenticator

api - 使用两因素身份验证的 instagram api 登录