CRYPT

crypt PLAINTEXT,SALT

Encrypts a string exactly like the crypt(3) function in the C library. Useful for checking the password file for lousy passwords, amongst other things. Only the guys wearing white hats should do this.

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"; }

Of course, typing in your own password to whoever asks you for it is unwise.

Back to functions