Command Line PHP

I am making a simple command line PHP program. Currently, when the user types in his password, you can see it on the screen in plain text. How can I make the password either not be echoed on the screen or have the password be echoed on the screen as asterisks?

$pass = "";
    while($pass != "password")
     {
      echo "Enter your login password and press ENTER.\n\n\n";
      $pass = trim(fgets(STDIN)); // reads one line from STDIN
     } // END WHILE LOOP THAT CHECKS PASSWORD

Thanks,
kea
LVL 2
keakathleenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

iamanindianCommented:
This seems a bit difficult...I will also like to know any possible solution to this. A by-passing way would be to open a web-page with password fields...& capture the password from the webpage & pass on to the CLI.

Otherwise.....hmnn....sorry friend...I am of no more help here.

Regards
WC
hernst42Commented:
AFAIK using STDIN it is not possible to suppress the echoed chars as they are written directly onto the screen before the same char is passed to STDIN. It might be possible if you open the device of the keyboard directly not using STDIN, but don't know which device you need to use in this case. like
$keyb = fopen('COM1:', 'r');

keakathleenAuthor Commented:
iamanindian  -

The webpage idea is interesting and one that I have thought of, but it's probably not the most ideal situation for what I want to do. I might have to use this idea as a backup plan.

hernst42 -

I think you might be on the right track. I'm still pretty new to the whole input/output thing, but you did give me an idea/question. Is there a way where we can bypass the user input to a temp text file and temporarily read the password from this text file? After reading, could we delete the file and continue to echo future user input back to the screen? If so, how might this be done?

Thanks to everyone who is helping.

hernst42Commented:
Have a look at http://jenseng.com/archives/000044.html which states that such a thing might only be possible via Windows-Scripting.

Reading the content of a field is done via file_get_contents. But how you get the password into that textfile without echoing it to screen first in a DOS-box I don't know. You can execute scripts or batch files with exec in php.

You might ask in the Windows area here for such a script/help on that topic

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.