Last active
August 29, 2015 14:05
-
-
Save nicklasos/06dc9795d8f3c8663d51 to your computer and use it in GitHub Desktop.
Prompt password
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Interactively prompts for input without echoing to the terminal. | |
* Requires a bash shell or Windows and won't work with | |
* safe_mode settings (Uses `shell_exec`) | |
* | |
* @see http://us.php.net/manual/en/function.ncurses-noecho.php | |
* @see http://us.php.net/manual/en/function.ncurses-getch.php | |
* | |
* Works only on normal OS, not in windows. | |
*/ | |
function prompt_silent($prompt = "Enter Password: ") | |
{ | |
$command = "/usr/bin/env bash -c 'echo OK'"; | |
if (rtrim(shell_exec($command)) !== 'OK') { | |
trigger_error("Can't invoke bash"); | |
return null; | |
} | |
$command = | |
"/usr/bin/env bash -c 'read -s -p \"" . | |
addslashes($prompt) . | |
"\" mypassword && echo \$mypassword'"; | |
$password = rtrim(shell_exec($command)); | |
return $password; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment