diff --git a/application/Espo/Core/Console/Commands/SetPassword.php b/application/Espo/Core/Console/Commands/SetPassword.php index 1dfa829a80..d1f0d681a6 100644 --- a/application/Espo/Core/Console/Commands/SetPassword.php +++ b/application/Espo/Core/Console/Commands/SetPassword.php @@ -76,7 +76,7 @@ class SetPassword implements Command $io->writeLine("Enter a new password:"); - $password = $io->readLine(); + $password = $io->readSecretLine(); if (!$password) { $io->writeLine("Password can not be empty."); diff --git a/application/Espo/Core/Console/IO.php b/application/Espo/Core/Console/IO.php index d985c50490..fb165cbcd8 100644 --- a/application/Espo/Core/Console/IO.php +++ b/application/Espo/Core/Console/IO.php @@ -64,6 +64,19 @@ class IO * Read a line from input. A string is trimmed. */ public function readLine(): string + { + return $this->readLineInternal(); + } + + /** + * Read a secret line from input. A string is trimmed. + */ + public function readSecretLine(): string + { + return $this->readLineInternal(true); + } + + private function readLineInternal(bool $secret = false): string { $resource = fopen('php://stdin', 'r'); @@ -71,8 +84,16 @@ class IO throw new RuntimeException("Could not open stdin."); } + if ($secret && !self::isWindows()) { + shell_exec('stty -echo'); + } + $readString = fgets($resource); + if ($secret && !self::isWindows()) { + shell_exec('stty echo'); + } + if ($readString === false) { $readString = ''; } @@ -84,6 +105,11 @@ class IO return $string; } + private static function isWindows(): bool + { + return strcasecmp(substr(PHP_OS, 0, 3), 'WIN') === 0; + } + /** * Set exit-status. *