I tried with @Assert\MinLength but it seems to check after encoding the password when it’s long enought in everycase. How to put the constraint before encoding?
I can’t think of anything better that to count the number of symbols with strlen after binding the registration form, but I don’t think this will be a good way. And also I’m not sure that even this will work, I’m not sure when exactly the encoding is done.
Any suggestions will be appreciated! Thank you in advance!
The problem is that you’re using one field for two purposes: storing a password in plain text and encoded form. What you need is a field for each purpose:
Only the
$passwordfield is persisted to the database and it’s not shown in forms so that users can’t edit it.Also you need a Doctrine event listener — or some other code — that checks if
$plainPasswordis not empty, and if it’s not, encode its value and put it into$password.Use the
security.encoder_factoryservice to get the encoder you’ve setup in your security configuration and use it to encode passwords. Also, check my ElnurBlowfishPasswordEncoderBundle.