asp.net - 在自己的 asp.net 项目中使用 Google Authenticator 进行两因素身份验证?

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

您好,我创建了自己的 asp.net 项目(不是 MVC)。现在我想使用 Google Authenticator 实现两因素身份验证。因此,当用户获得注册时,用户将获得 key 或获得 QR 图像并使用其 Android 手机进行设置。对于登录,他们需要来自谷歌身份验证器应用程序的 key 。

我在asp.net 中得到了很少的MVC 代码。我需要如何集成到 asp.net 应用程序(非 MVC)中的步骤 请指导我如何实现此任何示例将不胜感激。

谢谢

最佳答案

要添加 Google 身份验证,您需要以下内容

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
using System.Text;
using System.Web.Profile;
using System.Web.Security;
using Google.Authenticator;

获取 Google.Authenticator;在这里查看 https://www.nuget.org/packages/GoogleAuthenticator

现在设置谷歌身份验证。
TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
var setupInfo = tfa.GenerateSetupCode("Name of the app", "More info ABout the App", "SuperSecretKeyGoesHere", 300 , 300//the width and height of the Qr Code);

string qrCodeImageUrl = setupInfo.QrCodeSetupImageUrl; //  assigning the Qr code information + URL to string
string manualEntrySetupCode = setupInfo.ManualEntryKey; // show the Manual Entry Key for the users that don't have app or phone
Image1.ImageUrl = qrCodeImageUrl;// showing the qr code on the page "linking the string to image element"
Label1.Text = manualEntrySetupCode; // showing the manual Entry setup code for the users that can not use their phone

您可以更改 SuperSecretKeyGoesHere为您想要的任何值,但请确保它超过 10 个字符,否则生成的手动输入 key 将不起作用。
现在您可以使用文本框和按钮单击检查用户输入

此位将查看用户条目并查看是否正常
string user_enter=TextBox1.Text;
TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
bool isCorrectPIN = tfa.ValidateTwoFactorPIN("SuperSecretKeyGoesHere", user_enter);
if (isCorrectPIN == true)
{
Label2.Text = "i am cool";

}
else
{

Label2.Text = "i am Fool";
}

关于asp.net - 在自己的 asp.net 项目中使用 Google Authenticator 进行两因素身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23308701/

相关文章:

javascript - 使用 Duo Security Admin API 创建用户

.net - 是否有关于如何在 .NET 应用程序中实现 Google Authenticator 的教程?

security - 给定带有时间戳的旧值是否可以预测 future 的 2FA 值?

asp.net - 有没有办法获取所有 MIME 类型而不是编写大量的 case 语句?

c# - 从 int 到短字符串的 2 路加密

javascript - 使用 jQuery 延迟 .net 文件上传?

ios - 在 iOS 上自动启动 Google Authenticator 应用

android - 如何从 android studio 应用程序将 json 发送到 asp.net api Controller ?

.net-core - 在 IdentityServer4 和 Dotnet Core Identity 中使用带有身份验证 (oidc) 的 sms otp

android - 是否可以将 Android 手机用作 2FA 设备?