|
|
(view this code in a separate window)
#!/usr/bin/perl
# crypt.pl
#
# A little program to create a crypt(3) string
# based on user input. Not the prettiest
# thing in the world.
#
# Copyright 2001, James Lee
# Released under GPL
$salts='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/.';
print "Salt: ";
chomp($salt = <STDIN>);
# Pick a salt unless they selected one that's valid
$salt = substr($salts,rand(length($salts)),1) .
substr($salts,rand(length($salts)),1) unless $salt =~ /^[$salts]{2}/;
print "Plaintext password: ";
system '/bin/stty -echo';
chomp($passwd = <STDIN>);
system '/bin/stty echo';
print "\nThe encrypted password is: ", crypt($passwd, $salt), "\n";
|