perlfunc
gods
<P>
crypt - one-way passwd-style encryption
<P>
<HR>
<P>
crypt
<FONT SIZE=-1>PLAINTEXT,SALT</FONT>
<P>
<HR>
<P>
Encrypts a string exactly like the
<CODE>crypt(3)</CODE> function in the
<FONT SIZE=-1>C</FONT> library (assuming that you actually have a version there that has not been extirpated as a potential munition). This can prove useful for checking the password file for lousy passwords, amongst other things. Only the guys wearing white hats should do this.
<P>
Note that [perlfunc:crypt|crypt()] is intended to be a one-way function, much like breaking eggs to make an omelette. There is no (known) corresponding decrypt function. As a result, this function isn't all that useful for cryptography. (For that, see your nearby
<FONT SIZE=-1>CPAN</FONT> mirror.)
<P>
Here's an example that makes sure that whoever runs this program knows
their own password:
<P>
<PRE> $pwd = (getpwuid($<))[1];
$salt = substr($pwd, 0, 2);
</PRE>
<P>
<PRE> system "stty -echo";
print "Password: ";
chop($word = <STDIN>);
print "\n";
system "stty echo";
</PRE>
<P>
<PRE> if (crypt($word, $salt) ne $pwd) {
die "Sorry...\n";
} else {
print "ok\n";
}
</PRE>
<P>
Of course, typing in your own password to whoever asks you for it is
unwise.
<HR>