I'm trying to pre-populate a database with some User objects, but when I call $user->setPassword('some-password');
and then save the user object, the string 'some-password' is stored directly in the database, instead of the hashed+salted password.
My DataFixture class:
// Acme/SecurityBundle/DataFixtures/ORM/LoadUserData.php
<?php
namespace Acme\SecurityBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Acme\SecurityBundle\Entity\User;
class LoadUserData implements FixtureInterface
{
public function load(ObjectManager $manager)
{
$userAdmin = new User();
$userAdmin->setUsername('System');
$userAdmin->setEmail('system@example.com');
$userAdmin->setPassword('test');
$manager->persist($userAdmin);
$manager->flush();
}
}
And the relevant database output:
id username email salt password
1 System system@example.com 3f92m2tqa2kg8cookg84s4sow80880g test
Call setPlainPassword instead.
setPlainPassword works for me.
Here a sample class to create an admin user via ORM Fixtures:
Above worked for me, so I got some conclusion:
1. must use the setPlainPassword
2. must setEnabled(true)
Since you are using FOSUserBundle, you can use
UserManager
to do this. I would use this code (assuming you have$this->container
set):This worked for me
Note the difference when setting the password. Querying the database you find