加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-core-mvc – 使用asp.net核心的google身份验证器

发布时间:2020-12-16 07:07:01 所属栏目:asp.Net 来源:网络整理
导读:除了短信和电子邮件之外,Google身份验证器是否还有任何示例实现作为双因素身份验证实施? 找到一个样本. Sample Google Authenticator using asp.net 但是在使用asp.net核心时会有很多变化. 解决方法 您可以使用AspNetCore.Totp. https://github.com/damirku
除了短信和电子邮件之外,Google身份验证器是否还有任何示例实现作为双因素身份验证实施?

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

但是在使用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);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读