Created
September 21, 2009 11:37
-
-
Save cstar/190199 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -wl | |
use strict; | |
use Crypt::PasswdMD5 qw(unix_md5_crypt); | |
my @salt = ( '.', '/', 0 .. 9, 'A' .. 'Z', 'a' .. 'z' ); | |
# this takes password as argument: good for simple example, bad for | |
# security (perldoc -q password) | |
my $password = shift || die "usage: $0 password"; | |
my %encrypted; | |
# generate traditional (weak!) DES password, and more modern md5 | |
$encrypted{des} = crypt( $password, gensalt(2) ); | |
$encrypted{md5} = unix_md5_crypt( $password, gensalt(8) ); | |
print "$_ $encrypted{$_}" for sort keys %encrypted; | |
# uses global @salt to construct salt string of requested length | |
sub gensalt { | |
my $count = shift; | |
my $salt; | |
for (1..$count) { | |
$salt .= (@salt)[rand @salt]; | |
} | |
return $salt; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment