develooper Front page | perl.beginners | Postings from January 2002

Crypt function explanation

Thread Next
January 5, 2002 14:59
Crypt function explanation
Message ID:
Hi, below is a piece of code from the perl man pages.

My question deals with: crypt PLAINTEXT, SALT

Can someone please explain what the SALT is used for, HOW should it be set,
that is,
how many characters long it should be etc.

There is little explanation besides the example in the manual, as well as
on the camel book.

Any advice and extra info is appreciated.

Thank you.


HereĀ‘s an example that makes sure that whoever runs this program knows
their own password:
$pwd = (getpwuid($<))[1];
$salt = substr($pwd, 0, 2);
system "stty -echo";
print "Password: ";
chop($word = <STDIN>);
print "\n";
system "stty echo";
if (crypt($word, $salt) ne $pwd) {
die "Sorry...\n";
} else {
print "ok\n";

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About