/**
* Internal function to execute the command.
*
* @param InputInterface $input The input to inject into the command.
* @param OutputInterface $output The output to inject into the command.
*
* @return integer The command exit code
*
* @since 4.0.0
*/
protected function doExecute(InputInterface $input, OutputInterface $output) : int
{
$this->configureIO($input, $output);
$this->username = $this->getStringFromOption('username', 'Please enter a username');
$this->ioStyle->title('Change password');
$userId = UserHelper::getUserId($this->username);
if (empty($userId)) {
$this->ioStyle->error("The user " . $this->username . " does not exist!");
return Command::FAILURE;
}
$user = User::getInstance($userId);
$this->password = $this->getStringFromOption('password', 'Please enter a new password');
$user->password = UserHelper::hashPassword($this->password);
if (!$user->save(true)) {
$this->ioStyle->error($user->getError());
return Command::FAILURE;
}
$this->ioStyle->success("Password changed!");
return Command::SUCCESS;
}