Banago\PHPloy\PHPloy::getPassword PHP 메소드

getPassword() 개인적인 메소드

Gets the password from user input, hiding password and replaces it with stars (*) if user users Unix / Mac.
private getPassword ( ) : string
리턴 string the user entered
    private function getPassword()
    {
        if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
            return trim(fgets(STDIN));
        }
        $oldStyle = shell_exec('stty -g');
        $password = '';
        shell_exec('stty -icanon -echo min 1 time 0');
        while (true) {
            $char = fgetc(STDIN);
            if ($char === "\n") {
                break;
            } elseif (ord($char) === 127) {
                if (strlen($password) > 0) {
                    fwrite(STDOUT, " ");
                    $password = substr($password, 0, -1);
                }
            } else {
                fwrite(STDOUT, '*');
                $password .= $char;
            }
        }
        shell_exec('stty ' . $oldStyle);
        return $password;
    }