我正在嘗試覆蓋FOSUserBundle中密碼的當前驗證。我嘗試了幾個選項,但仍然找不到解決方案。FOSUserBundle密碼驗證
爲了提高密碼的使用MINLENGTH,我創建了一個validation.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
?
這是我在努力,看看是否是我的問題的原因刪除。我現在把它們放回去驗證,它們似乎沒有什麼區別。 爲了清晰起見,我將在上面進行編輯以包含它們。 – MadManMonty 2012-02-09 13:35:16