gpt4 book ai didi

symfony - FOSUserBundle密码验证

转载 作者:行者123 更新时间:2023-12-04 04:22:44 25 4
gpt4 key购买 nike

我试图覆盖当前对FOSUserBundle中密码的验证。我尝试了一些选择,但仍然找不到解决方案。

为了增加密码的MinLength,我使用以下命令创建了一个validate.yml:

# src/Acme/UserBundle/Resources/config/validation.yml
Acme\UserBundle\Entity\User:
properties:
username:
- MinLength: { limit: 3, message: "Your username must have at least {{ limit }} characters." }
- MaxLength: { limit: 255, message: "The username is too long" }
- NotBlank: { message: "Please enter a username"}

plainPassword:
- NotBlank: { message: "Please enter a password"}
- MinLength: { limit: 8, message: "Your password must have at least {{ limit }} characters.", groups [Registration,Profile]}
- MaxLength: { limit: 255, message: "The password is too long" }

Acme\UserBundle\Form\Model\ChangePassword:
properties:
new:
- NotBlank: { message: "Please enter a new password", groups [ChangePassword]}
- MinLength: { limit: 8, message: "Your password must have at least {{ limit }} characters.", groups [ChangePassword]}
- MaxLength: { limit: 255, message: "The password is too long", groups [ChangePassword]}

Acme\UserBundle\Form\Model\ResetPassword:
new:
- NotBlank: { message: "Please enter a new password", groups [ResetPassword]}
- MinLength: { limit: 8, message: "Your new password must have at least {{ limit }} characters.", groups [ResetPassword]}
- MaxLength: { limit: 255, message: "The new password is too long", groups [ResetPassword]}

这对于 /register来说对我来说很好,但是在 /change-password上,来自FOSUserBundle的默认最小长度验证正在获得所有权。

为了更清楚地陈述我的问题,在FOSUserBundle中为密码设置MinLength的正确方法是什么,以确保它在所有地方都得到验证?

另外,用FOSUserBundle在ChangePassword中验证 oldpassword != newpassword的正确方法是什么?

最佳答案

validation.yml应该在覆盖FOS用户实体的同一个包中

代替Acme,您应该使用FOS,并且只需要一个验证集。

# src/Acme/UserBundle/Resources/config/validation.yml
FOS\UserBundle\Model\User:
properties:
username:
- MinLength: { limit: 3, message: "Your username must have at least {{ limit }} characters." }
- MaxLength: { limit: 255, message: "The username is too long" }
- NotBlank: { message: "Please enter a username"}

plainPassword:
- NotBlank: { message: "Please enter a password", groups:[Registration, ResetPassword, ChangePassword] }
- MinLength: { limit: 8, message: "Your password must have at least {{ limit }} characters.", groups:[Registration, ResetPassword, ChangePassword] }
- MaxLength: { limit: 255, message: "The password is too long", groups:[Registration, ResetPassword, ChangePassword] }

遇到麻烦时,请转至源头:
https://github.com/FriendsOfSymfony/FOSUserBundle/issues/987

关于symfony - FOSUserBundle密码验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9203411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com