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

前端 未结 7 1755
庸人自扰
庸人自扰 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:16

    /**
     * 添加用户
     * @param $param
     * @return int
     */
    public function doAdd($param)
    {
        $entity = new User();
        $em = $this->getEntityManager();
        $entity->setUsername($param['username'])
            ->setPlainPassword($param['password'])
            ->setEmail($param['email'])
            ->setEnabled(true)
            ->setRealName($param['realName']);
    
        $em->persist($entity);
        $em->flush();
        return $entity->getId();
    }
    

    Above worked for me, so I got some conclusion:
    1. must use the setPlainPassword
    2. must setEnabled(true)

提交回复
热议问题