在 Linux 底下可以真的顯示 * 號,但windows要readmode 為2才可讓我能成功enter,不過是enter完後才看到*號

use Term::ReadKey;
my $key = 0;
my $password = “”;
print ”
Please input your password: “;
# Start reading the keys
#ReadMode(4); # Disable the control keys for linux
ReadMode(2); # for Windows
while(ord($key = ReadKey(0)) != 10)
# This will continue until the Enter key is pressed (decimal value of 10)
{
$password = $password.$key;
print “*”;
}
ReadMode(0); #Reset the terminal once we are done
print “Your super secret password is: $password
“;

# ref: http://zh-tw.w3support.net/index.php?db=so&id=701078
# ref: http://forums.devshed.com/perl-programming-6/problem-with-readmode-under-use-term-readkey-462494.html

Related posts 相關文章
不要在瀏覽器上自動儲存自己的密碼,已有人被駭
More...
2020 年迎來了 PHP 8 與 Perl 7
More...
Apache htaccess 限制某頁面要輸入密碼 Password
More...
當 git clone 或 git pull 時就儲存帳密在當下不用再二次輸入
More...

作者

留言

撰寫回覆或留言

發佈留言必須填寫的電子郵件地址不會公開。