Command Line Password Prompt in PHP

后端 未结 10 1542
北海茫月
北海茫月 2020-11-30 21:48

I\'m writing a command line tool to help my web app. It needs a password to connect to the service. I\'d like the script to show a password prompt so I don\'t have to pass i

10条回答
  •  囚心锁ツ
    2020-11-30 22:28

    The below method works under Linux CLI but not under Windows CLI or Apache. It also only works with chars in the standard Ascii table (It would not take much to make it compatible with extended char sets though).

    I have put a bit of code in to protect against copy and paste passwords. If the bit between the two comments is removed then a password can be injected/pasted in.

    I hope this helps someone.

    0)
                        {
                            $strObscured=substr($strObscured,0,strlen($strObscured)-1);
                            echo(chr(27).chr(91)."D"." ".chr(27).chr(91)."D");
                        }
                    }
                    elseif ($strChar>=' ')
                    {
                        $strObscured.=$strChar;
                        echo($strMaskChar);
                        //echo(ord($strChar));
                    }
                }
            }
            readline_callback_handler_remove();
            return($strObscured);
        }
    ?>
    

提交回复
热议问题