Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 2: problem with passwords encryption

Tags:

symfony

I made a simple registration form with form builder. It seems I did everything totally like in the documentation and articles but I still can't make passwords to store in database not in a plain text.

Here are some files, please, help me.

security.yml: http://pastebin.com/4FwBaZQK
Acme\UserBundle\Entity\User: http://pastebin.com/iUGd4Cz1
Acme\SecurityBundke\Controller\SecurityController: http://pastebin.com/wTVy2zE2

like image 758
asmisha Avatar asked Dec 06 '22 19:12

asmisha


1 Answers

Check out the documentation on encoding user passwords.

The code snippet from the documentation should be applied to the user object after it's bound, but before it's persisted and flushed (so between lines 45 and 46 in your Security controller):

$factory = $this->get('security.encoder_factory');
$user = new Acme\UserBundle\Entity\User();

$encoder = $factory->getEncoder($user);
$password = $encoder->encodePassword($user->getPassword(), $user->getSalt());
$user->setPassword($password);
like image 107
Derek Stobbe Avatar answered Dec 10 '22 22:12

Derek Stobbe