首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FOSUserBundle密码验证

FOSUserBundle密码验证
EN

Stack Overflow用户
提问于 2012-02-09 07:50:56
回答 2查看 10.6K关注 0票数 10

我正在尝试覆盖FOSUserBundle中密码的当前验证。我试过几种方法,但还是找不到解决办法。

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

代码语言:javascript
复制
# 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的正确方法是什么

EN

回答 2

Stack Overflow用户

发布于 2013-09-19 04:34:53

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

您应该使用FOS而不是Acme,并且应该只需要一个验证集。

代码语言:javascript
复制
# 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

票数 4
EN

Stack Overflow用户

发布于 2012-02-09 16:26:10

您可以使用验证组

http://symfony.com/doc/2.0/book/validation.html#validation-groups

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9203411

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档