Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Custom Password Strength Estimator not working #59235

Closed as not planned
Closed as not planned
@attilajakab

Description

@attilajakab

Symfony version(s) affected

7.2.*

Description

Custom Password Strength Estimator not working when following the official guide, section Customizing the Password Strength Estimation:
https://symfony.com/doc/current/reference/constraints/PasswordStrength.html#customizing-the-password-strength-estimation

Results in error:

"Notice: Object of class App\\Validator\\CustomPasswordStrengthEstimator could not be converted to int"

In Symfony's Symfony\Component\Validator\Constraints\PasswordStrengthValidator in validate method the $strength variable should be of type integer, but instead it is the custom password strength estimator class object:
image

The __invoke method of the custom password strength estimator class not gets triggered:
image

How to reproduce

Create custom password strength estimator following the official guide, section Customizing the Password Strength Estimation:
https://symfony.com/doc/current/reference/constraints/PasswordStrength.html#customizing-the-password-strength-estimation

Assert the PasswordStrength constraint on User entity's password field:
image

Create a form type for password creation on User entity:
image

Try to submit a password through the form. The follow error will be returned:

"Notice: Object of class App\\Validator\\CustomPasswordStrengthEstimator could not be converted to int"

Possible Solution

It seems like on line 43 the custom password strength estimator class is instantiated, but then the object is not invoked, so the __invoke method of the customer estimator never gets triggered, thus not returning an integer, but it is the custom estimator class object itself inside $strength variable:
image

The proposed fix could be like this inside Symfony\Component\Validator\Constraints\PasswordStrengthValidator validate method:
image
Tested and is working as expected.

Additional Context

Using PHP 8.3.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions