feat(occ): allow admins to clear account passwords

Signed-off-by: Kent Delante <kent.delante@proton.me>
This commit is contained in:
Kent Delante 2026-01-20 09:46:35 +08:00
parent 42c0e5ffeb
commit 711bd2bc6d

View file

@ -43,6 +43,12 @@ class ResetPassword extends Base {
InputOption::VALUE_NONE,
'read password from environment variable NC_PASS/OC_PASS'
)
->addOption(
'no-password',
null,
InputOption::VALUE_NONE,
'Sets the password to blank'
)
;
}
@ -76,22 +82,32 @@ class ResetPassword extends Base {
}
}
$question = new Question('Enter a new password: ');
$question->setHidden(true);
$password = $helper->ask($input, $output, $question);
if ($input->getOption('no-password')) {
$question = new ConfirmationQuestion('Are you sure you want to clear the password for ' . $username . '?');
if ($password === null) {
$output->writeln('<error>Password cannot be empty!</error>');
return 1;
}
if (!$helper->ask($input, $output, $question)) {
return 1;
}
$question = new Question('Confirm the new password: ');
$question->setHidden(true);
$confirm = $helper->ask($input, $output, $question);
$password = '';
} else {
$question = new Question('Enter a new password: ');
$question->setHidden(true);
$password = $helper->ask($input, $output, $question);
if ($password !== $confirm) {
$output->writeln('<error>Passwords did not match!</error>');
return 1;
if ($password === null) {
$output->writeln('<error>Password cannot be empty!</error>');
return 1;
}
$question = new Question('Confirm the new password: ');
$question->setHidden(true);
$confirm = $helper->ask($input, $output, $question);
if ($password !== $confirm) {
$output->writeln('<error>Passwords did not match!</error>');
return 1;
}
}
} else {
$output->writeln('<error>Interactive input or --password-from-env is needed for entering a new password!</error>');