Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

perlfunc:crypt

by gods (Initiate)
on Aug 24, 1999 at 22:43 UTC ( [id://308]=perlfunc: print w/replies, xml ) Need Help??

crypt

See the current Perl documentation for crypt.

Here is our local, out-dated (pre-5.6) version:


crypt - one-way passwd-style encryption



crypt PLAINTEXT,SALT



Encrypts a string exactly like the crypt(3) function in the C 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.

Note that 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 CPAN mirror.)

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.


Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-03-19 07:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found