Don't input password in command, ask in prompt #1552

This commit is contained in:
the-djmaze 2024-04-23 18:03:04 +02:00
parent 372e4bc1c0
commit b7a11d42de

View file

@ -37,15 +37,12 @@ class Settings extends Base
)
->addArgument(
'pass',
InputArgument::REQUIRED,
InputArgument::OPTIONAL,
'The login passphrase'
)
;
}
protected function checkInput(InputInterface $input) {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
$uid = $input->getArgument('uid');
if (!$this->userManager->userExists($uid)) {
@ -57,6 +54,15 @@ class Settings extends Base
$this->config->setUserValue($uid, 'snappymail', 'snappymail-email', $sEmail);
$sPass = $input->getArgument('pass');
if (empty($sPass)) {
// Prompt on command line for value
if (\is_callable('readline')) {
$sPass = \readline("password: ");
} else {
echo "password: ";
$sPass = \stream_get_line(STDIN, 1024, PHP_EOL);
}
}
$sPass = ($sEmail && $sPass) ? SnappyMailHelper::encodePassword($sPass, \md5($sEmail)) : '';
$this->config->setUserValue($uid, 'snappymail', 'passphrase', $sPass);
return 0;