diff --git a/core/Command/User/ResetPassword.php b/core/Command/User/ResetPassword.php index c1759533d3996..cdda5df1c1835 100644 --- a/core/Command/User/ResetPassword.php +++ b/core/Command/User/ResetPassword.php @@ -43,6 +43,12 @@ protected function configure() { 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 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } - $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('Password cannot be empty!'); - 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('Passwords did not match!'); - return 1; + if ($password === null) { + $output->writeln('Password cannot be empty!'); + return 1; + } + + $question = new Question('Confirm the new password: '); + $question->setHidden(true); + $confirm = $helper->ask($input, $output, $question); + + if ($password !== $confirm) { + $output->writeln('Passwords did not match!'); + return 1; + } } } else { $output->writeln('Interactive input or --password-from-env is needed for entering a new password!');