Skip to content

Commit 06ed32f

Browse files
committed
doc: 更新 MFA 示例
1 parent 3f7aa6c commit 06ed32f

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed
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)