真的不可能编写一个php cli密码提示来隐藏Windows中的密码吗? [英] Is it really not possible to write a php cli password prompt that hides the password in windows?

查看:65
本文介绍了真的不可能编写一个php cli密码提示来隐藏Windows中的密码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了几个小时试图找到一种在php中编写跨平台密码提示的方法,该提示隐藏了用户输入的密码.尽管可以通过使用stty -echo在Unix环境中轻松完成此操作,但我尝试了各种passthru()和system()调用方法,以使Windows进行相同的操作均无济于事.

I have spent several hours trying to find a means of writing a cross platform password prompt in php that hides the password that is input by the user. While this is easily accomplished in Unix environments through the use of stty -echo, I have tried various means of passthru() and system() calls to make windows do the same thing to no avail.

我尝试过:

passthru('set /p pass=Password: ');
system('echo %pass% > out.txt');
$pass = file_get_contents('out.txt', 'r');

这似乎挂在passthru('set/p pass = Password:');行,不允许我输入任何文本,必须使用Ctrl-c将其杀死.

This seems to hang on the passthru('set /p pass=Password: '); line without allowing me to input any text and must be killed with a Ctrl-c.

我还尝试了fgetc和fgets的各种方法,并打印退格字符以隐藏输入,因为这在其他语言中也有效.但是,PHP似乎无法在回车之前与文本进行交互.

I have also tried various methods of fgetc and fgets and printing backspace characters to hide the input since this works in other languages. However, PHP does not appear to be able to interact with text prior to a carriage return.

我真的很想找到一种方法来完成这项工作,这是不可能完成的任务还是可以完成的事情?

I would really like to find a way to make this work, is this an impossible task or is this something that can be done?

请注意,我知道我可以将php脚本包装在批处理文件中,然后将密码作为命令行参数传递,但这在我这种情况下不起作用.

Note that I am aware that I could wrap the php script in a batch file and pass the password as a command line argument, but that doesn't work for me in this case.

推荐答案

这是Windows解决方案,使用PHP的COM扩展名.我在Windows XP和PHP 5.2.6上对此进行了测试.

Here's a Windows solution, using the COM extension for PHP. I tested this on Windows XP with PHP 5.2.6.

<?php

$pwObj = new Com('ScriptPW.Password');

print "Password: ";
$passwd = $pwObj->getPassword();

echo "Your password is $passwd\n";

?>

这篇关于真的不可能编写一个php cli密码提示来隐藏Windows中的密码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆