-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Validator] Document PasswordStrength
constraint
#18124
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
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
PasswordStrength
constraint
MrYamous
reviewed
Mar 26, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think minScore
option could be listed too in Available Options section
fabpot
added a commit
to symfony/symfony
that referenced
this pull request
Mar 26, 2023
This PR was squashed before being merged into the 6.3 branch. Discussion ---------- [Validator] New `PasswordStrength` constraint | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | yes | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | none | License | MIT | Doc PR | symfony/symfony-docs#18124 This PR adds a new constraint `PasswordStrength`. This constraint is able to determine if the password strength (or any other string) fulfils with the threshold. It leverages on [`bjeavons/zxcvbn-php`](https://github.com/bjeavons/zxcvbn-php) which is required when this constraint is used. Example: ```php <?php declare(strict_types=1); namespace App\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\PasswordType; use Symfony\Component\Form\Extension\Core\Type\RepeatedType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\PasswordStrength; final class ChangePasswordFormType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options): void { $restrictedData = $options['restrictedData'] ?? []; $builder ->add('plainPassword', RepeatedType::class, [ 'type' => PasswordType::class, 'options' => [ 'attr' => [ 'autocomplete' => 'new-password', ], ], 'first_options' => [ 'constraints' => [ new NotBlank(), new PasswordStrength(['restrictedData' => $restrictedData]) ], 'label' => 'New password', ], 'second_options' => [ 'label' => 'Repeat the new password', ], 'mapped' => false, ]) ; } public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'restrictedData' => [], ]) ->setAllowedTypes('restrictedData', 'string[]') ; } } ``` Then from e.g. a controller ```php $form = $this->createForm(ChangePasswordFormType::class, null, [ 'restrictedData' => [ $user->getUsername(), $user->getEmail(), $user->getGivenName(), $user->getFamilyName(), 'ApplicationName', // Arbitrary data ], ]); ``` It can be added as a property attribute: ```php <?php declare(strict_types=1); namespace App\Form; use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\PasswordStrength; final class ChangePasswordFormData { #[NotBlank] #[PasswordStrength] public string $password = ''; } ``` Options: * `lowStrengthMessage`: the message in case of a weak password (default: `The password strength is too low. Please use a stronger password.`) * `minScore`: 0 means a weak password, 4 means a very good password (default: `2`) * `restrictedData`: a list of restricted data e.g. user information such as ID, username, email, given name, last name or application information (default: `[]`) * `restrictedDataMessage`: the message in case of the restricted data in the password (default: `The password contains at least one restricted data: {{ wordList }}.`) Commits ------- 1d93f5c [Validator] New `PasswordStrength` constraint
Reverted by @chalasr in symfony/symfony#49831 |
0e27613
to
f703400
Compare
f703400
to
ec51dd2
Compare
fabpot
added a commit
to symfony/symfony
that referenced
this pull request
Mar 31, 2023
… builtin solution (Spomky) This PR was merged into the 6.3 branch. Discussion ---------- [Validator] Remove `bjeavons/zxcvbn-php` in favor of a builtin solution | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #49831 | License | MIT | Doc PR | symfony/symfony-docs#18124 will be updated As per the discussion in #49831, this PR aims at removing `bjeavons/zxcvbn-php` in favor of a builtin solution. The password strength estimator is a PHP implementation of [deanilvincent/check-password-strength](https://github.com/deanilvincent/check-password-strength/blob/master/index.js), but can be changed at will. Commits ------- 6b2bf22 Remove bjeavons/zxcvbn-php in favor of a builtin solution
The new PR was merged |
OskarStark
approved these changes
Mar 31, 2023
Thank you Florent. |
javiereguiluz
added a commit
that referenced
this pull request
Mar 4, 2025
…eference (stof) This PR was merged into the 6.4 branch. Discussion ---------- Remove non-existent password_strength setting from the reference This was added in #18124 when documenting the new constraint, but the implementation does not have a configuration setting for that in the FrameworkBundle configuration. I spotted this when I saw it being in the reference without the usual info about the type of values and wanting to fix it. Commits ------- a87223b Remove non-existent password_strength setting from the reference
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
These modifications are proposed as per
symfony/symfony#49789=> symfony/symfony#49856