setName('user:reset-password') ->setDescription('Change user password') ->addArgument('username', InputArgument::REQUIRED, 'Username') ; } protected function execute(InputInterface $input, OutputInterface $output) { $helper = $this->getHelper('question'); $username = $input->getArgument('username'); $passwordQuestion = new Question('What is the new password for '.$username.'? (characters are not printed)'.PHP_EOL); $passwordQuestion->setHidden(true); $passwordQuestion->setHiddenFallback(false); $password = $helper->ask($input, $output, $passwordQuestion); $confirmationQuestion = new Question('Confirmation:'.PHP_EOL); $confirmationQuestion->setHidden(true); $confirmationQuestion->setHiddenFallback(false); $confirmation = $helper->ask($input, $output, $confirmationQuestion); if ($this->validatePassword($output, $password, $confirmation)) { $this->resetPassword($output, $username, $password); } } private function validatePassword(OutputInterface $output, $password, $confirmation) { list($valid, $errors) = $this->passwordResetValidator->validateModification(array( 'password' => $password, 'confirmation' => $confirmation, )); if (!$valid) { foreach ($errors as $error_list) { foreach ($error_list as $error) { $output->writeln(''.$error.''); } } } return $valid; } private function resetPassword(OutputInterface $output, $username, $password) { $userId = $this->userModel->getIdByUsername($username); if (empty($userId)) { $output->writeln('User not found'); return false; } if (!$this->userModel->update(array('id' => $userId, 'password' => $password))) { $output->writeln('Unable to update password'); return false; } $output->writeln('Password updated successfully'); return true; } }