2012-02-08 21 views
9

Sto tentando di ignorare la convalida corrente per le password in FOSUserBundle. Ho provato alcune opzioni, ma non riesco ancora a trovare la soluzione.Convalida password FOSUserBundle

Per aumentare minLength della parola, ho creato un validation.yml con:

# 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]} 

Questo sta lavorando per me bene sul /register, ma sul /change-password il default min convalida lunghezza da FOSUserBundle sta prendendo possesso.

Per specificare più chiaramente la mia domanda, qual è il modo corretto per impostare la lunghezza minima della password in FOSUserBundle per assicurarsi che sia convalidata ovunque?

Inoltre, qual è l'approccio corretto con FOSUserBundle per verificare all'interno di ChangePassword che oldpassword != newpassword?

risposta

4

validation.yml dovrebbe essere nello stesso fascio che sovrascrive l'impresa utilizzatrice FOS

Invece di Acme si dovrebbe usare FOS e si dovrebbe solo bisogno un set di validazione.

# 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] } 

Quando in difficoltà, andare alla fonte: https://github.com/FriendsOfSymfony/FOSUserBundle/issues/987

+1

questo non sembra essere la sintassi corretta per la validazione della lunghezza basata su questo http://symfony.com/doc/current/reference/constraints/Length.html – gondo

Problemi correlati