File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed
Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -232,3 +232,8 @@ Events
232232------
233233
234234See :doc: `Events </events >`
235+
236+ Validating Google Authenticator Codes in Forms
237+ ----------------------------------------------
238+
239+ See :doc: `Validating Two-Factor Codes in Forms </validator_constraints >`
Original file line number Diff line number Diff line change @@ -251,3 +251,8 @@ Events
251251------
252252
253253See :doc: `Events </events >`
254+
255+ Validating TOTP Codes in Forms
256+ ------------------------------
257+
258+ See :doc: `Validating Two-Factor Codes in Forms </validator_constraints >`
Original file line number Diff line number Diff line change 1+ Validating Two-Factor Codes in Forms
2+ =====================================
3+
4+ When building forms that require users to enter a two-factor authentication code, you can use the built-in validation
5+ constraints provided by the bundle to automatically verify the code against the authenticator provider.
6+
7+ TOTP Code Validation
8+ --------------------
9+
10+ Use the ``UserTotpCode `` constraint when you want to validate codes from the **TOTP ** authentication provider.
11+
12+ .. code-block :: php
13+
14+ use Scheb\TwoFactorBundle\Security\TwoFactor\Validator\Constraints\UserTotpCode;
15+ use Symfony\Component\Validator\Constraints as Assert;
16+
17+ class SecuritySettingsForm
18+ {
19+ #[Assert\NotBlank(message: 'Please enter your authentication code')]
20+ #[UserTotpCode(message: 'The authentication code is invalid')]
21+ public string $totpCode;
22+ }
23+
24+ Google Authenticator Code Validation
25+ ------------------------------------
26+
27+ Use the ``UserGoogleTotpCode `` constraint when you want to validate codes from the **Google Authenticator ** provider.
28+
29+ .. code-block :: php
30+
31+ use Scheb\TwoFactorBundle\Security\TwoFactor\Validator\Constraints\UserGoogleTotpCode;
32+ use Symfony\Component\Validator\Constraints as Assert;
33+
34+ class LoginForm
35+ {
36+ #[Assert\NotBlank(message: 'Please enter your authentication code')]
37+ #[UserTotpCode(message: 'The authentication code is invalid')]
38+ public string $authCode;
39+ }
You can’t perform that action at this time.
0 commit comments