-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] New PasswordStrength
constraint
#49789
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
[Validator] New PasswordStrength
constraint
#49789
Conversation
We have something really similar in our application, so I think it's a good idea to have this feature in the core |
1fd5fa3
to
c6500cb
Compare
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.
would definitely use it :)
]; | ||
yield [ | ||
new PasswordStrength([ | ||
'restrictedData' => ['symfony'], |
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.
this is very nice
may I ask you to "complete" your PR desc with your usage of dump($userData);
with the constraint?
or injecting for example the security user to define the username/email in the list, this would be very valuable
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.
The dump
statement is a wrong copy/paste.
I will add an example when the form factory is used with user/application data.
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.
that will be wonderful for showcasing real usage in the doc repo after :)
I like the proposal 😃💪🏻 |
src/Symfony/Component/Validator/Constraints/PasswordStrength.php
Outdated
Show resolved
Hide resolved
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.
Love it as well (it has been on my todo list for a long time now, thank you for working on it).
PasswordStrength
constraint
+1 |
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.
Can you add an entry in the component CHANGELOG file?
805ed9f
to
8eb69fc
Compare
Yes. Done. |
@@ -152,7 +152,8 @@ | |||
"symfony/security-acl": "~2.8|~3.0", | |||
"twig/cssinliner-extra": "^2.12|^3", | |||
"twig/inky-extra": "^2.12|^3", | |||
"twig/markdown-extra": "^2.12|^3" | |||
"twig/markdown-extra": "^2.12|^3", | |||
"bjeavons/zxcvbn-php": "^1.0" |
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.
Should be added in the validator component composer.json as well.
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.
Yes indeed I missed it. I have just added it as a dev dependency and in the suggest
section as well.
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.
#37093 that's a long standing feature 👍
The docs should probably point to the OWASP recommandations to reduce misuses.
@@ -62,6 +63,7 @@ | |||
"symfony/yaml": "", | |||
"symfony/config": "", | |||
"egulias/email-validator": "Strict (RFC compliant) email validation", | |||
"bjeavons/zxcvbn-php": "Password strength estimation used by the PasswordStrength constraint", |
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.
Let's remove this one. It's not needed, and discovery happens with docs and/or auto-completion, ... but never via the suggest Composer thingy IMHO.
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.
OK I understand. I removed this line.
3c0c947
to
1d93f5c
Compare
Thank you @Spomky. |
Considered for reversion in #49831 |
…omky) This PR was merged into the 6.3 branch. Discussion ---------- [Validator] Document `PasswordStrength` constraint These modifications are proposed as per ~symfony/symfony#49789 => symfony/symfony#49856 Commits ------- ec51dd2 PasswordStrength Documentation pages
This PR adds a new constraint
PasswordStrength
. This constraint is able to determine if the password strength (or any other string) fulfils with the minimum requirement.It leverages on
bjeavons/zxcvbn-php
which is required when this constraint is used.Example:
Then from e.g. a controller
It can be added as a property attribute:
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 }}.
)