Reputation: 4588
I tried to override FOSUserBundle's password constraints this way:
XXX/XXXBundle/Resources/config/validation.yml
XXX\XXXBundle\Entity\User:
properties:
username:
- NotBlank: ~
email:
- NotBlank: ~
- Email: { groups: [online] }
plainPassword:
- MinLength: { limit: 6, message: "Your pw must have at least {{ limit }} characters.", groups: [Registration, Profile, ResetPassword, ChangePassword] }
- Regex: { pattern: "/(?=.*[A-Za-z])(?=.*[0-9])[A-Za-z0-9]+/", message: "Das Passwort muss eine Ziffer und Buchstaben enthalten.", groups: [Registration, Profile, ResetPassword, ChangePassword] }
This doesn't work for me. When I try to change the password, 2 chars are accepted. I have tried it with and without validation groups - no change.
Any ideas?
Upvotes: 3
Views: 1708
Reputation: 4588
We got around this using:
FOS\UserBundle\Form\Model\ChangePassword:
properties:
new:
- Regex:
pattern: "/(?=.*[A-Za-z])(?=.*[0-9])[A-Za-z0-9]+/"
message: "%yourtext%."
groups: [ChangePassword, ResetPassword]
Upvotes: 2
Reputation: 123
I have had the exact same problem and my regex was invalid, the result was always true so the validation passes. Check your pattern just to be sure its working as expected.
Upvotes: 0