Enabling two-factor authentication

Two-factor authentication can be enabled in an ASP.NET Core web application by uncommenting the following code that comes with the ASP.NET Core web application project template. You can use the same or equivalent logic when working with an empty project template. To store your phone number where the application will send the code to perform the second step of authentication can be done by uncommenting the following code snippet from the Index view page of ManageController.

Here is the code of Manage/Index.cshtml:

    @(Model.PhoneNumber ?? "None") 
@if (Model.PhoneNumber != null)
{
<br />
<a asp-controller="Manage"
asp-action="AddPhoneNumber"
class="btn-bracketed">Change</a>
<form asp-controller="Manage"
asp-action="RemovePhoneNumber"
method="post"> [<button type="submit"
class="btn-link">Remove</button>]
</form>
}
else
{
<a asp-controller="Manage"
asp-action="AddPhoneNumber"
class="btn-bracketed">Add</a>
}

Enable Two-factor authentication by uncommenting the following code:

    @if (Model.TwoFactor) 
{
<form asp-controller="Manage"
asp-action="DisableTwoFactorAuthentication"
method="post" class="form-horizontal">
Enabled <button type="submit" class="btn-link
btn-bracketed">Disable</button>
</form>
}
else
{
<form asp-controller="Manage"
asp-action="EnableTwoFactorAuthentication"
method="post" class="form-horizontal">
<button type="submit" class="btn-link
btn-bracketed">Enable</button> Disabled
</form>
}

Once the user is registered, you can go to the user settings and enable Two-Factor Authentication and specify the mobile number where the SMS code will be sent, as shown in the following screenshot:

When you add the phone number and submit, it will send you the code over SMS, which should be specified in the next screen to verify it:

Specify the code you receive and click on Submit. Once the code is verified, it will be redirected to the account settings page and show the number added, as follows:

Now, when you try to log in again, it will ask you to select the Two-Factor Authentication Provider. As in the previous example, we have only enabled 2FA with Phone so we can select that and submit.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.168.214