Symfony2 $user->setPassword() updates password as plain text [DataFixtures + FOSUserBundle]

前端 未结 7 1760
庸人自扰
庸人自扰 2020-12-23 13:44

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 stri

7条回答
  •  不思量自难忘°
    2020-12-23 14:13

    This worked for me

      public function load(ObjectManager $manager){
        $userAdmin = new User();
        $userAdmin->setUsername('admin');
        $userAdmin->setPlainPassword('admin');
        $userAdmin->setEmail('admin@gmail.com');
        $userAdmin->setEnabled(true);
    
        $manager->persist($userAdmin);
        $manager->flush();
      }
    

    Note the difference when setting the password. Querying the database you find

    id  username    username_canonical  email              email_canonical  enabled salt                            password    
      2 admin       admin               admin@gmail.com    admin@gmail.com  1       4gm0bx6jzocgksw0wws8kck04kg40o8 m2ZyJM2+oBIzt/NZdnOX4nFvjV/SWTU1qJqe6dWZ0UwLF5gB8N...
    

提交回复
热议问题