PERL crypt Function

Syntax

crypt EXPR,SALT


Definition and Usage

Encrypts the string EXPR using the system crypt( ) function. The value of SALT is used to select an encrypted version from one of a number of variations. Note that there is no equivalent decryption function. You cannot decrypt a string that has been encrypted in this way. It’s normally used one way, first to encrypt a string, and then to encrypt a password to compare against the encrypted string. If you’re using it in this form, then consider supplying the encrypted password as the SALT.

Return Value

  • Encrypted string

Example

Here’s an example that makes sure that whoever runs this program knows their password:
#!/usr/bin/perl

$pwd = (getpwuid($<))[1];

system "stty -echo";
print "Password: ";
chomp($word = <STDIN>);
print "n";
system "stty echo";

if (crypt($word, $pwd) ne $pwd) {
die "Sorry wrong passwordn";
} else {
print "ok, correct passwordn";
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s