Skip to content

Commit 3ad7405

Browse files
committed
Add docs on validation constraints
1 parent fb90a9a commit 3ad7405

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

doc/providers/google.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,8 @@ Events
232232
------
233233

234234
See :doc:`Events </events>`
235+
236+
Validating Google Authenticator Codes in Forms
237+
----------------------------------------------
238+
239+
See :doc:`Validating Two-Factor Codes in Forms </validator_constraints>`

doc/providers/totp.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,8 @@ Events
251251
------
252252

253253
See :doc:`Events </events>`
254+
255+
Validating TOTP Codes in Forms
256+
------------------------------
257+
258+
See :doc:`Validating Two-Factor Codes in Forms </validator_constraints>`

doc/validator_constraints.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
}

0 commit comments

Comments
 (0)