任何人都可以给我一个示例代码,让用户输入密码两次并比较它们并打印文本(如果它们是否正确),就像我们创建新用户时一样。提前谢谢......
答案 0 :(得分:2)
$pwd = (getpwuid($<))[1];
system "stty -echo";
print "Password: ";
chomp($word = <STDIN>);
print "\n";
system "stty echo";
if (crypt($word, $pwd) ne $pwd) {
die "Sorry...\n";
} else {
print "ok\n";
}
根据您的需要进行修改。
答案 1 :(得分:0)
这里是基于ephemient的提示的答案..我不需要我删除的第一行,如果案件ne假设是eq,可能意味着相等:)它看起来有效..
system "stty -echo";
print "Password: ";
chomp($word = <STDIN>);
print "Password again: ";
chomp($pwd = <STDIN>);
print "\n";
system "stty echo";
if (crypt($word, $pwd) eq $pwd) {
die "Sorry...\n";
} else {
print "ok\n";
}
答案 2 :(得分:0)
system "stty -echo";
print "Password: ";
chomp(my $password = <STDIN>);
print "\nPassword again: ";
chomp(my $check_again = <STDIN>);
print "\n";
system "stty echo";
if ($password ne $check_again) {
die "Sorry...\n";
} else {
print "ok\n";
}