Last active
January 7, 2025 11:51
-
-
Save JBlond/fa4a5b8cc6a065a65110b88b956b4fd7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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`) | |
| */ | |
| function prompt_silent($prompt = "Enter Password:") { | |
| if (preg_match('/^win/i', PHP_OS)) { | |
| $vbscript = sys_get_temp_dir() . 'prompt_password.vbs'; | |
| file_put_contents( | |
| $vbscript, 'wscript.echo(InputBox("' | |
| . addslashes($prompt) | |
| . '", "", "password here"))'); | |
| $command = "cscript //nologo " . escapeshellarg($vbscript); | |
| $password = rtrim(shell_exec($command)); | |
| unlink($vbscript); | |
| return $password; | |
| } else { | |
| $command = "/usr/bin/env bash -c 'echo OK'"; | |
| if (rtrim(shell_exec($command)) !== 'OK') { | |
| trigger_error("Can't invoke bash"); | |
| return; | |
| } | |
| $command = "/usr/bin/env bash -c 'read -s -p "" | |
| . addslashes($prompt) | |
| . "" mypassword && echo $mypassword'"; | |
| $password = rtrim(shell_exec($command)); | |
| echo "n"; | |
| return $password; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment