除了短信和电子邮件之外,是否有任何谷歌身份验证器的示例实现作为两因素身份验证实现?
找到一个样本。 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/