Last Updated: March 29, 2021
·
8.189K
· jrgns

Simple Random Password in Symfony 2

From withing a Controller, do the following to get a random 12 digit alphanumeric password:

$tokenGenerator = $this->container->get('fos_user.util.token_generator');
$password = substr($tokenGenerator->generateToken(), 0, 12);

1 Response
Add your response

You should mention that if someone uses this he needs FOSUserBundle too.

over 1 year ago ·