prompt_for_password: remove external bash dependency

This commit is contained in:
Benjamin Renard 2024-02-20 21:13:33 +01:00
parent fb67ffdf3b
commit 99c350267f

View file

@ -412,16 +412,10 @@ Additional parameters:
* @return string * @return string
*/ */
public static function prompt_for_password($prompt=null) { public static function prompt_for_password($prompt=null) {
// Check bash is available print($prompt?_($prompt):I18n::_("Please enter password:"));
$command = "/usr/bin/env bash -c 'echo OK'"; system('stty -echo');
if (rtrim(shell_exec($command)) !== 'OK') $password = trim(fgets(STDIN));
Log::fatal(I18n::_("Can't invoke bash. Can't ask password prompt.")); system('stty echo');
$command = "/usr/bin/env bash -c 'read -s -p \"";
$command .= addslashes($prompt?_($prompt):I18n::_("Please enter password:"));
$command .= "\" mypassword && echo \$mypassword'";
$password = rtrim(shell_exec($command));
echo "\n";
return $password; return $password;
} }