Skip to content
Snippets Groups Projects
Commit febf8a5f authored by Marcus Eibrink-Lunzenauer's avatar Marcus Eibrink-Lunzenauer
Browse files

Add `--confirmation`/`--no-confirmation` to read password from stdin.

Closes #3910

Merge request studip/studip!2766
parent 5974e61b
No related branches found
No related tags found
No related merge requests found
......@@ -29,6 +29,13 @@ class ChangePassword extends Command
InputArgument::REQUIRED,
'The username of the user whose password will be changed.'
);
$this->addOption(
'confirmation',
null,
InputOption::VALUE_NEGATABLE,
'Enter password twice to confirm it',
true
);
}
protected function execute(InputInterface $input, OutputInterface $output)
......@@ -41,24 +48,33 @@ class ChangePassword extends Command
return Command::FAILURE;
}
$passwords = $this->askPassword($input, $output);
$status = $this->changePassword($user, ...$passwords);
if (isset($status)) {
$output->writeln('<error>' . $status . '</error>');
return Command::FAILURE;
}
return Command::SUCCESS;
}
/**
* @return array{string,string} a pair of strings containing the password and its confirmation
*/
private function askPassword(InputInterface $input, OutputInterface $output): array
{
$helper = $this->getHelper('question');
$question = new Question('New password: ', '');
$question->setHidden(true);
$password = $helper->ask($input, $output, $question);
$question2 = new Question('Re-type password: ', '');
$question2->setHidden(true);
$password2 = $helper->ask($input, $output, $question2);
$status = $this->changePassword($user, $password, $password2);
if (isset($status)) {
$output->writeln('<error>' . $status . '</error>');
return Command::FAILURE;
}
$password = $helper->ask($input, $output, $question);
$password2 = $input->getOption('confirmation') ? $helper->ask($input, $output, $question2) : $password;
return Command::SUCCESS;
return [$password, $password2];
}
private function changePassword(\User $user, string $password, string $password2): ?string
......@@ -88,8 +104,6 @@ class ChangePassword extends Command
return 'The password could not be set.';
}
StudipLog::USER_NEWPWD($user->id, null, 'Passwort neu gesetzt', null, $user->id);
return null;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment