Sat*_*jit 5 google-authenticator two-factor-authentication asp.net-core-mvc
除了短信和电子邮件之外,Google身份验证器是否还有任何示例实现作为双因素身份验证实施?
找到一个样本. 使用asp.net示例Google身份验证器
但是在使用asp.net核心时会有很多变化.
您可以使用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 totpValidator = new TotpValidator();
bool isCorrectPIN = totpValidator.Validate("YourSuperSecretKeyHere", pin);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2820 次 |
| 最近记录: |