Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Validator] MakePasswordStrengthValidator::estimateStrength() public#54881
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
[Validator] MakePasswordStrengthValidator::estimateStrength() public#54881
Uh oh!
There was an error while loading.Please reload this page.
Conversation
src/Symfony/Component/Validator/Tests/Password/PasswordStrengthEstimatorTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
smnandre commentedMay 11, 2024
What about: In the component
In the framework bundle
|
yalit commentedMay 12, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Thanks for the proposition and ideas. I didn't thought about the deprecation but if you add the service a a Closure in the DI as well, wouldn't the deprecation not kick in. And building on your proposition:
The idea of the interface is for, in the future, to be able to pass in the constructor another implementation of that interface if a custom strength estimation is needed while using by default the one of the component EDIT : I pushed the proposal above |
chalasr commentedMay 12, 2024
Thanks for the PR. As the the proposed service is not about validation per se, should it be located elsewhere than in the Validator component? PasswordHasher or its own component maybe? If we feel like it's not worth it, then it's probably not worth making it a first-class service either and we don't need to change anything at all given the use case can already be solved using dependency injection (the validator service can be decorated or replaced to be given a different closure for strength estimation) |
xabbuh commentedMay 13, 2024
Reading the code changes I am not sure that we need the deprecation of being able to pass a closure. Do we win anything in the future when being able to pass a closure wouldn't be possible anymore? |
src/Symfony/Component/Validator/Constraints/PasswordStrengthValidator.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
xabbuh commentedMay 13, 2024
Do you have a real use case for this or is being able to get the strength enough for the moment? |
src/Symfony/Component/Validator/Password/PasswordStrengthEstimatorInterface.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Validator/Constraints/PasswordStrengthValidator.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Validator/Constraints/PasswordStrengthValidator.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Validator/Tests/Constraints/PasswordStrengthValidatorWithClosureTest.phpShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
yalit commentedMay 13, 2024
@xabbuh the Use case is to get the score of any string (the target would be to display a sort of score visualization when the user fills the password on the frontend using the exact same definition as the backend while not re-developing the alrgorithm in the frontend) Hence the proposal of extracting that into a dedicated class. The replacement of the Closure by the interface was to align on the way the DI is made in Symfony based on services but it can be avoided if found not pertinent. @chalasr Originally I thought adding that service into the Security component as it felt more linked to the security level of a Password but it felt too much changes in different places and so kept it inside the Validator Component. I have no problem for it to find another place as this one in the Symfony ecosystem and for me to update the PR to match the need. (wouldn't it create an unwanted dependency in the Validator component?) |
xabbuh commentedMay 13, 2024
But are we talking about being able to get the strength before the validation is performed or should the information be provided to users in advance? |
yalit commentedMay 13, 2024
the idea is to provide the information before the validation is performed (while they are typing) but using the same algo/checks that will be done during the validation |
xabbuh commentedMay 13, 2024
Thank you for the clarification. To fulfill this feature request extracting the method into a separate class indeed makes sense to me. |
nicolas-grekas left a comment
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 feel like this is too much abstraction for a specific use case (which does make sense).
Instead, I'd suggestjust making theestimateStrength method public. Then, consumers can type-hint forClosure and leverage PHP's and Symfony's capability to turn a method into a closure to achieve decoupling.
Pierstoval commentedMay 16, 2024
There is another reason I find in making a new service based on a new interface: custom password strength. I had the case in the past, we were using another version of Symfony, and password strength was expected to be really specific, and the current implementation in Symfony, even though it's good, didn't fit the specs we had, so we developed our own validator for that. Just being able to override one service with our own "password strength calculator" would have been great back then, because it would still have triggered the whole Symfony Validation system, while allowing us to also use the exact same service to display the HTML tag in the frontend displaying the strength. Double effect on this. |
nicolas-grekas commentedMay 16, 2024
@Pierstoval this use case is already supported: just pass a closure to the constructor. |
derrabus commentedMay 16, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Extracting that interface would result in a more formal contract however. But what makes this weird is that thevalidator component would expose a service that estimates password strength. I would expect to find this kind of service in security-core maybe or the password-hasher component. That being said, the use-case might be just too much of a niche to justify exposing a service for it. Making that method public (and documenting how to have that closure injected) would indeed cover all use-cases. |
nicolas-grekas commentedMay 16, 2024
I wouldn't expose a service, just a public static method. If ppl want to change the estimator, they would just have to redefine the PasswordStrengthValidator service.
Yes, that's my point. We provide full flexibility by just making the method public and nothing else. |
yalit commentedMay 21, 2024
I've rollback-ed the changes to make only the function estimateStrength public in the Validator. |
src/Symfony/Component/Validator/Tests/Constraints/PasswordStrengthValidatorWithClosureTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Validator/Tests/Constraints/PasswordStrengthValidatorWithClosureTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
derrabus commentedMay 21, 2024
Please apply the patch suggested by fabbot and eliminate all merge commits by rebasing your PR onto the 7.2 branch. |
PasswordStrengthValidator::estimateStrength() public36f7f44 to5e96a1bCompare
nicolas-grekas left a comment
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 just force-pushed the changes suggested by@derrabus)
18cfd0a toe058d92Comparederrabus commentedMay 21, 2024
Thank you@yalit. |
yalit commentedMay 21, 2024
No problem. Thanks for the review and support 👍 |
Uh oh!
There was an error while loading.Please reload this page.
Linked to the PasswordStrength Constraint, the need is to be able to get the "strength" of a password and not just only if it's strong enough. For instance, the need is to show a "score" bar in the frontend.
Currently, the strength is being computed by a private function within the PasswordStrengthValidator not accessible directly. The proposed change is to extract that computation in a specific
PasswordStrengthEstimatorservice for it to be accessible from the "external" world.The best way to do so would be to inject the service in the Validator constructor but doing that it would break the compatibility as the current constructor is receiving a Closure to allow for self-strength computation.
So here the service is called from within the Validator directly and so maintaining the Backward Compatibility
I created the same PR but with no Backward Compatibility (service injected in the constructor) here :#54882