entityManager ->getRepository(User::class) ->findOneBy(['username' => $username]); } public function _setPassword(User $user, $password) { $defaultEncoder = new \Symfony\Component\PasswordHasher\Hasher\MessageDigestPasswordHasher('sha512', true, 5000); $encoders = [ User::class => $defaultEncoder, ]; $encoderFactory = new EncoderFactory($encoders); $user->setPassword( $encoderFactory->getEncoder($user)->encodePassword($password, $user->getSalt()) ); $this->entityManager->flush($user); } public function configure() { $this->setName('chill:user:set_password') ->addArgument('username', InputArgument::REQUIRED, 'the user\'s ' .'username you want to change password') ->addArgument('password', InputArgument::OPTIONAL, 'the new password'); } public function execute(InputInterface $input, OutputInterface $output): int { $user = $this->_getUser($input->getArgument('username')); if (null === $user) { throw new \LogicException("The user with username '".$input->getArgument('username')."' is not found"); } $password = $input->getArgument('password'); if (null === $password) { $dialog = $this->getHelperSet()->get('dialog'); $password = $dialog->askHiddenResponse($output, 'the new password :' .''); } $this->_setPassword($user, $password); return Command::SUCCESS; } }