我试图用这种方式覆盖fosuserbundle的密码限制:
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] }
这对我不起作用。当我试图更改密码时,接受2个字符。我试过有或没有验证组-没有变化。
有什么想法吗?
最佳答案
我们通过以下方式解决了这个问题:
FOS\UserBundle\Form\Model\ChangePassword:
properties:
new:
- Regex:
pattern: "/(?=.*[A-Za-z])(?=.*[0-9])[A-Za-z0-9]+/"
message: "%yourtext%."
groups: [ChangePassword, ResetPassword]