Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I generate salt and confirmation_token entries for migrated users with FOSUserBundle

I am resurrecting a website that has been down for a few years and I am migrating everything to Symfony2. I was able to get all of my old user database entries into the fos_user table. The only problem is that the salt and confirmation_token entries are empty because users were were not created the standard way. I want all users to reset their passwords, so I'm not worried about the old hashed passwords at all. How can I generate the entries for 13,000 users at once? Maybe I need to override the controller to create the salt and confirmation_token each time a password is requested? Do methods already exist for this? It seems like someone else would have had this problem before.

Thanks

like image 909
rooter Avatar asked May 28 '13 04:05

rooter


1 Answers

I solved this by overriding the fosUserBundle Resetting controller. Instructions can be found here.

I forced generation of a new toke with these lines:

$tokenGenerator = $this->container->get('fos_user.util.token_generator');
$user->setConfirmationToken($tokenGenerator->generateToken());

I was able to generate the salt values with a simple SQL query.

UPDATE fos_user set salt = SUBSTRING(MD5(RAND()) FROM 1 FOR 31) WHERE salt IS NULL
like image 165
rooter Avatar answered Nov 14 '22 23:11

rooter