Skip to content

Commit a92587e

Browse files
doc(MFA): add enable 2FA sample code (#5994)
* chore: bump version 9.6.1-beta04 * test: bump version 9.6.1-beta05 * chore: test push auto * style: 更新样式 * doc: 更新 MFA 示例 * chore: bump version 9.6.1-beta04 Co-Authored-By: ChenHan819 <[email protected]> * chore: bump version 9.6.1-beta03 --------- Co-authored-by: ChenHan819 <[email protected]>
1 parent d456d8c commit a92587e

File tree

4 files changed

+113
-1
lines changed

4 files changed

+113
-1
lines changed

src/BootstrapBlazor.Server/Components/Samples/Tutorials/MFA/Login.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<div class="bb-sign-body">
1010
<div class="mb-2">Username or email address</div>
1111
<input type="text" class="form-control mb-3" value="[email protected]" />
12-
<div class="d-flex mb-2">
12+
<div class="d-flex justify-content-between mb-2">
1313
<div>Password</div>
1414
<div>Forgot password?</div>
1515
</div>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
@page "/tutorials/mfa/two-factor/register"
2+
@inject IOptionsMonitor<WebsiteOptions> WebsiteOption
3+
@inject ITotpService TotpService
4+
5+
<div class="bb-sign">
6+
<div class="text-center">
7+
<img src="@WebsiteOption.CurrentValue.GetAssetUrl("images/logo.png")" />
8+
<h3>Two-factor methods</h3>
9+
</div>
10+
<div class="bb-sign-body">
11+
<div class="mb-2"><b>Authenticator app</b></div>
12+
<div class="mb-3">
13+
Authenticator apps and browser extensions like <code>1Password</code>, <code>Authy</code>, <code>Microsoft Authenticator</code>, <code>Google Authenticator</code>, etc. generate one-time passwords that are used as a second factor to verify your identity when prompted during sign-in.
14+
</div>
15+
<div class="mb-2"><b>Scan the QR code</b></div>
16+
<div class="mb-3">
17+
Use an authenticator app or browser extension to scan. Learn more about enabling 2FA.
18+
</div>
19+
<div class="bb-sign-qr">
20+
<QRCode Content="@_content" Width="190"></QRCode>
21+
</div>
22+
<div class="mb-3"><b>Verify the code from the app</b></div>
23+
<input type="password" class="form-control" @bind="@_code" />
24+
<button type="button" class="form-control bg-success text-white mt-3" @onclick="OnRegister">Save</button>
25+
</div>
26+
</div>
27+
28+
@code {
29+
[Inject, NotNull]
30+
private NavigationManager? NavigationManager { get; set; }
31+
32+
private string? _content;
33+
34+
private string? _code;
35+
36+
protected override void OnInitialized()
37+
{
38+
base.OnInitialized();
39+
40+
_content = TotpService.GenerateOtpUri(new OtpOptions()
41+
{
42+
AccountName = "BootstrapBlazor",
43+
IssuerName = "BootstrapBlazor",
44+
UserName = "Simulator",
45+
SecretKey = "OMM2LVLFX6QJHMYI",
46+
Algorithm = OtpHashMode.Sha1,
47+
Type = OtpType.Totp
48+
});
49+
}
50+
51+
private void OnRegister()
52+
{
53+
if (_code == TotpService.Compute("OMM2LVLFX6QJHMYI"))
54+
{
55+
NavigationManager.NavigateTo("/tutorials/mfa/two-factor/app");
56+
}
57+
}
58+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
.bb-sign {
2+
margin: 0 auto;
3+
width: 640px;
4+
padding: 0 1rem;
5+
}
6+
7+
.bb-sign img {
8+
background-color: var(--bb-primary-color);
9+
border-radius: 50%;
10+
margin-block: 2rem;
11+
}
12+
13+
.bb-sign h1 {
14+
font-size: 24px;
15+
font-weight: 300;
16+
letter-spacing: -0.5px;
17+
margin-block-end: 1rem;
18+
}
19+
20+
.bb-sign-body {
21+
background-color: #f6f8fa;
22+
border: 1px solid var(--bs-border-color);
23+
border-radius: var(--bs-border-radius);
24+
padding: 1rem;
25+
}
26+
27+
.bb-sign-body img {
28+
width: 32px;
29+
height: auto;
30+
margin: 0;
31+
margin-block-end: 1rem;
32+
}
33+
34+
.bb-sign-body h3 {
35+
font-size: 20px;
36+
font-weight: 400;
37+
}
38+
39+
.bb-sign-qr {
40+
margin-top: 1rem;
41+
margin-bottom: 1rem;
42+
}
43+
44+
::deep .qrcode {
45+
padding: .5rem;
46+
border: 1px solid var(--bs-border-color);
47+
border-radius: var(--bs-border-radius);
48+
display: inline-flex;
49+
align-items: center;
50+
justify-items: center;
51+
}

src/BootstrapBlazor.Server/Components/Samples/Tutorials/MFA/TwoFactor.razor

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@
1717
<div class="mt-1">
1818
<a href="./tutorials/mfa/two-factor/app">Use your authenticator app</a>
1919
</div>
20+
<div class="mt-3">
21+
<a href="./tutorials/mfa/two-factor/register">Enable Two-factor methods</a>
22+
</div>
2023
</div>
2124
</div>

0 commit comments

Comments
 (0)