perl password confirmation
can anyone give me a sample code for letting a user to enter a password two times and compare them and print a text if they are co开发者_如何学Crrect or not, like when we create a new user. Thanks in advance...
From perldoc -f crypt,
$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";
}
Modify to suit your needs.
here is the answer based on ephemient's hint.. I dont need the first line that i removed and in if case ne suppose to be eq, probably means equal:)it looks it works..
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";
}
crypt is a red herring.
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";
}
精彩评论