如何使用Google Authenticator在ASP.NET Core中设置两因素身份验证

本文介绍了如何在ASP.NET Core应用中使用Google Authenticator设置两因素身份验证。首先,需要在手机上配置Google Authenticator应用,使用Web应用生成的QR码。登录时,用户需输入应用生成的六位数密码以完成验证。文章详细阐述了创建MVC Web应用、添加QR码配置、身份验证过程等步骤。
摘要由CSDN通过智能技术生成

介绍 (Introduction)

In this article, we are going to learn how to perform two-factor authentication in an ASP.NET Core application using the Google Authenticator app.

在本文中,我们将学习如何使用Google Authenticator应用程序在ASP.NET Core应用程序中执行两因素身份验证。

To use it, you need to configure the Google Authenticator app on your smartphone using the QR code generated in the web app. When you login to the web application, you have to enter a six-digit pin that will be generated in the app to finish the two-factor authentication. The key generated in the app will be unique to your userID, and is a time-based one-time password (TOTP) — that is, it will expire after a certain time.

要使用它,您需要使用网络应用程序中生成的QR码在智能手机上配置Google Authenticator应用程序。 登录Web应用程序时,您必须输入一个将在应用程序中生成的六位数密码,以完成两因素身份验证。 应用程序中生成的密钥对于您的用户ID是唯一的,并且是基于时间的一次性密码(TOTP),也就是说,它将在特定时间后失效。

先决条件 (Prerequisites)

  • Install .NET Core 2.0.0 or above SDK from here.

    此处安装.NET Core 2.0.0或更高版本的SDK。

  • Install the latest version of Visual Studio 2017 Community Edition from here.

    此处安装最新版本的Visual Studio 2017社区版。

源代码 (Source Code)

Before proceeding, I would recommend that you get the source code from GitHub

在继续之前,我建议您从GitHub获取源代码。

创建MVC Web应用程序 (Create the MVC Web Application)

Open Visual Studio and select File >> New >> Project. After selecting the project, a “New Project” dialog will open. Select .NET Core inside the Visual C# menu from the left panel. Then, select “ASP.NET Core Web Application” from the available project types. Name the project “TwoFactAuth” and press OK.

打开Visual Studio,然后选择“文件>>新建>>项目”。 选择项目后,将打开“新建项目”对话框。 从左侧面板的Visual C#菜单中选择.NET Core。 然后,从可用的项目类型中选择“ ASP.NET Core Web应用程序”。 将项目命名为“ TwoFactAuth”,然后按OK。

After clicking OK, a new dialog will open asking you to select the project template. You can see two drop-down menus at the top left of the template window. Select “.NET Core” and “ASP.NET Core 2.0” from these drop-downs. Then, select the “Web application (Model-View-Controller)” template. Click on “Change Authentication” button. A “Change Authentication” dialog box will open. Select “Individual User Account” and click OK. Now, click OK again to create your web app.

单击确定后,将打开一个新对话框,要求您选择项目模板。 您可以在模板窗口的左上方看到两个下拉菜单。 从这些下拉列表中选择“ .NET Core”和“ ASP.NET Core 2.0”。 然后,选择“ Web应用程序(模型-视图-控制器)”模板。 点击“更改身份验证”按钮。 将打开“更改身份验证”对话框。 选择“个人用户帐户”,然后单击“确定”。 现在,再次单击“确定”以创建您的Web应用程序。

添加QR码以配置两因素身份验证 (Adding QR Codes to configure two-factor authentication)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值