Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
[Validator] feat : add password strength estimator related documentation#19910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
javiereguiluz merged 1 commit intosymfony:7.2fromyalit:fix_19903_password_strength_get_or_overrideMay 28, 2024
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletionsvalidation/passwordStrength/get_or_override_estimate_strength.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| How to Get or Override the Default Password Strength Estimation Algorithm | ||
| ========================================================================= | ||
| Within the :class:`Symfony\\Component\\Validator\\Constraints\\PasswordStrengthValidator` a `dedicated function`_ is used to estimate the strength of the given password. This function can be retrieved directly from the :class:`Symfony\\Component\\Validator\\Constraints\\PasswordStrengthValidator` class and can also be overridden. | ||
| Get the default Password strength | ||
| --------------------------------- | ||
| In case of need to retrieve the actual strength of a password (e.g. compute the score and display it when the user has defined a password), the ``estimateStrength`` `dedicated function`_ of the :class:`Symfony\\Component\\Validator\\Constraints\\PasswordStrengthValidator` is a public static function, therefore this function can be retrieved directly from the `PasswordStrengthValidator` class.:: | ||
| use Symfony\Component\Validator\Constraints\PasswordStrengthValidator; | ||
| $passwordEstimatedStrength = PasswordStrengthValidator::estimateStrength($password); | ||
| Override the default Password strength estimation algorithm | ||
| ----------------------------------------------------------- | ||
| If you need to override the default password strength estimation algorithm, you can pass a ``Closure`` to the :class:`Symfony\\Component\\Validator\\Constraints\\PasswordStrengthValidator` constructor. This can be done using the :doc:`/service_container/service_closures`. | ||
| First, create a custom password strength estimation algorithm within a dedicated callable class.:: | ||
| namespace App\Validator; | ||
| class CustomPasswordStrengthEstimator | ||
| { | ||
| /** | ||
| * @param string $password | ||
| * | ||
| * @return PasswordStrength::STRENGTH_* | ||
| */ | ||
| public function __invoke(string $password): int | ||
| { | ||
| // Your custom password strength estimation algorithm | ||
| } | ||
| } | ||
| Then, configure the :class:`Symfony\\Component\\Validator\\Constraints\\PasswordStrengthValidator` service to use the custom password strength estimation algorithm.:: | ||
| # config/services.yaml | ||
| services: | ||
| custom_password_strength_estimator: | ||
| class: App\Validator\CustomPasswordStrengthEstimator | ||
| Symfony\Component\Validator\Constraints\PasswordStrengthValidator: | ||
| arguments: [!service_closure '@custom_password_strength_estimator'] | ||
| .. _`dedicated function`: https://github.com/symfony/symfony/blob/85db734e06e8cb32365810958326d48084bf48ba/src/Symfony/Component/Validator/Constraints/PasswordStrengthValidator.php#L53-L90 |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.