Skip to content

Instantly share code, notes, and snippets.

Created December 18, 2012 18:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anonymous/4330554 to your computer and use it in GitHub Desktop.
Password prompt
<?php
public function insilent()
{
$oldStyle = shell_exec('stty -g');
shell_exec('stty -echo');
$value = $this->stdin->fgets();
shell_exec('stty ' . $oldStyle);
return $value;
}
// Here's a Windows solution, using the COM extension for PHP. I tested this on Windows XP with PHP 5.2.6.
$pwObj = new Com('ScriptPW.Password');
print "Password: ";
$passwd = $pwObj->getPassword();
echo "Your password is $passwd\n";
// http://stackoverflow.com/questions/297850/is-it-really-not-possible-to-write-a-php-cli-password-prompt-that-hides-the-pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment