您好,我创建了自己的 asp.net 项目(不是 MVC)。现在我想使用 Google Authenticator 实现两因素身份验证。因此,当用户获得注册时,用户将获得密钥或获取 QR 图像并使用它的 android 手机进行设置。对于登录,他们需要来自谷歌身份验证器应用程序的密钥。
我在 asp.net 中得到了一些 MVC 代码。我需要如何集成到 asp.net 应用程序(不是 MVC)中的步骤请指导我如何实现这个任何示例将不胜感激。
谢谢
您好,我创建了自己的 asp.net 项目(不是 MVC)。现在我想使用 Google Authenticator 实现两因素身份验证。因此,当用户获得注册时,用户将获得密钥或获取 QR 图像并使用它的 android 手机进行设置。对于登录,他们需要来自谷歌身份验证器应用程序的密钥。
我在 asp.net 中得到了一些 MVC 代码。我需要如何集成到 asp.net 应用程序(不是 MVC)中的步骤请指导我如何实现这个任何示例将不胜感激。
谢谢
To Add Google authentication you need the following
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;
To get the Google.Authenticator; check here https://www.nuget.org/packages/GoogleAuthenticator
now setting up the Google authentication.
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
you can change the SuperSecretKeyGoesHere
to any value that you want, but make sure it has more than 10 character otherwise the manual entry key that is generated will not work.
Now you can check the user input with text box and button click
this bit will look at the user entry and see if its ok
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 Web API 和 AngularJS 中的两个因素身份验证使用 Google Authenticator 希望这能回答您的问题。