I want to know how to check an arbitrary password against the validation rules defined in validation.xml
. I created an admin page where admin users can create other admin users. I want to validate these users using the same rules that are used when anonymous users register for their own account at the /register
page. From what I can see, these rules are defined in validation.xml
.
So basically I want to do something like this:
$userManager = $container->get('fos_user.user_manager');
$user = $userManager->createUser();
$user->setPlainPassword('1');
$arrayOfErrors = functionThatValidatesUserPassword($user);
or even call a function on the password directly like this:
$arrayOfErrors = functionThatValidatesUserPassword('1');
What should I use to replace functionThatValidatesUserPassword
here?
I thought the validator service might work, but when I try
$validator = $this->get('validator');
$errors = $validator->validate($user);
print_r($errors);exit;
I just get an empty list of errors. I was expecting to see an error saying "The password is too short" which is what you get if you register for an account with the same password on the /register
page.
I am on Symfony 3.4 and FosUserBundle 2.0.
While searching for answers to my question, I found the following two posts describing how to override the rules defined in the validation.xml
file.
I do plan on overriding the validation rules, but for now I just want to validate my password using the built-in rules that come with FosUserBundle.