asmisha
asmisha

Reputation: 75

Symfony 2: problem with passwords encryption

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

Upvotes: 4

Views: 9138

Answers (1)

Problematic
Problematic

Reputation: 17678

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);

Upvotes: 15

Related Questions