public function setPassword(User $user, $password)
    {
        $encoder = $this->container->get('security.encoder_factory')
            ->getEncoder($user);

        $salt = $this->createSalt();

        $encryptedPassword = $encoder->encodePassword($password, $salt);

        $user
            ->setPassword($encryptedPassword)
            ->setSalt($salt);
    }
public function setPassword(User $user, $password)
    {
        $encoder = $this->container->get('security.encoder_factory')
            ->getEncoder($user);

        $salt = $this->createSalt();

        $encryptedPassword = $encoder->encodePassword($password, $salt);

        $user
            ->setPassword($encryptedPassword)
            ->setSalt($salt);
    }
public function setPassword ( User $ user , $ password ) { $ encoder = $ this -> container -> get ( 'security.encoder_factory' ) -> getEncoder ( $ user ) ; $ salt = $ this -> createSalt ( ) ; $ encryptedPassword = $ encoder -> encodePassword ( $ password , $ salt ) ; $ user -> setPassword ( $ encryptedPassword ) -> setSalt ( $ salt ) ; }
Set salt, encrypt password and set it on the user object

@param User $user User object to manipulate
@param string $password Password to encrypt and store
Set salt encrypt password and set it on the user object