perl and md5 crypt
How would I fix this to generate MD5 passwords ?
I am writing a tiny script that creates student users and assigns the
passwords, sets permissions to chmod 711, sets up user fetchmail, setups the muttrc,
and setups a generic signiture, and a generic web-site.
I am stumped on the, borrowed, cyrpt section of my program.
This function does not store MD5 passwords:
Clear text input:
user = tester3
passwd = board
test command from command line:
useradd tester3 -g student -p 11UuRFQQF.DIE
Output Created by function in the Shadow MD5 file
tester3:11UuRFQQF.DIE:11701:0:99999:7:::
When I try:
ted@albert:~/admin$ su - tester3
Password:
su: Authentication failure
Sorry.
passwd tester3
creates this:
It should look like this MD5 style:
tester3:$1$sx6dzguz$IyKiUC3Ua2MCOFDZxppzk1:11701:0:99999:7:::
!/usr/bin/perl
my $myuser = ("tester3");
my $passwd = ("board");
$salted=salt_pass();
print ("$salted");
#########
# salt_pass
#########
sub salt_pass {
srand (time ^ $$ ^ unpack ("%L*", `ps xlwwa le | gzip -f`));
@range = (qw(. /), '0'..'9','a'..'z','A'..'Z');
$x = int scalar @range;
sub randchar {
join '', map $range[rand $x], 1..shift||1;
print ("$_\n");
}
sub encrypt {
my $salt;
$salt = randchar(2);
$crypted = crypt $key, $salt;
}
$key = $passwd;
$cypted = encrypt;
$salted = $crypted;
}
Reply to: