SKMTH
SKMTH

Reputation: 622

FOS user bundle password validation

I'm trying to set up minimum character count limit for my users' password, using FOS User bundle, whether it is for registration or password reset

I've checked the documentation and searched on github issues / stackoverflow, but nothing is crystal clear to me. It seems that everyone has a different way to do this, and none seems to be matching my case.

First, I checked the documentation: https://symfony.com/doc/current/bundles/FOSUserBundle/overriding_validation.html

So I went to the validation.xml file and changed the plainpassword min size from 2 to 8:

<option name="min">8</option>

Yes, directly in the bundle. It was just to test. But it didn't changed anything

One of the way I found was to put an @Assert regex in the user entity, on the plainPassword field. https://github.com/FriendsOfSymfony/FOSUserBundle/issues/986

Problem is: my passwords are encrypted, so I don't have any plain password field. Passwords get salted in the usersController upon registration, so this way fo doing is not applicable to my API, I believe.

So how would you achieve this in a quick and rather easy way?

Cheers!

Upvotes: 1

Views: 2035

Answers (1)

D. Schreier
D. Schreier

Reputation: 1788

As @IwanWijaya said you can follow the documentation https://symfony.com/doc/3.3/bundles/override.html

src/Acme/UserBundle/Resources/config/validation.yml

FOS\UserBundle\Model\User:
    properties:
        plainPassword:
            - NotBlank:
                groups: [AcmeValidation]
            - Length:
                min: 6
                minMessage: fos_user.password.short
                groups: [AcmeValidation]

Upvotes: 2

Related Questions