pjs/webtools/bonsai/trapdoor

27 строки
917 B
Perl
Executable File

#!/usr/bin/perl -wT
if (!defined $ARGV[0]) {
print "Usage: trapdoor PASSWORD\n";
exit 2;
}
# The following code was taking from Bugzilla's bz_crypt() subroutine
# The list of characters that can appear in a salt. Salts and hashes
# are both encoded as a sequence of characters from a set containing
# 64 characters, each one of which represents 6 bits of the salt/hash.
# The encoding is similar to BASE64, the difference being that the
# BASE64 plus sign (+) is replaced with a forward slash (/).
my @saltchars = (0..9, 'A'..'Z', 'a'..'z', '.', '/');
# Generate the salt. We use an 8 character (48 bit) salt for maximum
# security on systems whose crypt uses MD5. Systems with older
# versions of crypt will just use the first two characters of the salt.
my $salt = '';
for ( my $i=0 ; $i < 8 ; ++$i ) {
$salt .= $saltchars[rand(64)];
}
# Crypt the password.
print crypt($ARGV[0], $salt) . "\n";