【问题标题】:Two Factor Authentication using Google Authenticator in own asp.net project?在自己的 asp.net 项目中使用 Google Authenticator 进行两因素身份验证?
【发布时间】:2014-04-26 08:50:31
【问题描述】:

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

我在 asp.net 中获得了一些 MVC 代码。我需要如何在 asp.net 应用程序中集成的步骤(不是 MVC)请指导我如何实现这个任何示例将不胜感激。

谢谢

【问题讨论】:

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


【解决方案1】:

要添加 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

现在设置 Google 身份验证。

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 个字符,否则生成的手动输入密钥将不起作用。 现在您可以使用文本框和按钮单击来检查用户输入

此位将查看用户条目并查看其是否正常

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";
}

【讨论】:

    【解决方案2】:

    老问题,但我已经在博客中准确介绍了您的情况,您可以阅读帖子:Two Factor Authentication in ASP.NET Web API & AngularJS using Google Authenticator 希望这能回答您的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-30
      • 2020-09-13
      • 2019-01-04
      • 2015-12-08
      • 2018-07-30
      • 1970-01-01
      相关资源
      最近更新 更多