Created
August 29, 2013 04:33
-
-
Save jhargis/6374306 to your computer and use it in GitHub Desktop.
generate an htpasswd with perl script
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/env perl | |
if ($#ARGV < 1) { | |
die("Usage:\tUsername Password\n") | |
} | |
my $username = shift; | |
my $newpass = shift; | |
my $new_entry; | |
my @entry = split(':', $_); | |
$entry[1] = &encrypt_passwd($username, $newpass); | |
$new_entry = join(':', @entry); | |
print "$username$new_entry\n"; | |
sub encrypt_passwd { | |
my($user,$pass)=@_; | |
my($nslat,$week,$now,$pert1,$pert2); | |
my(@salt_set)=('a'..'z','A'..'Z','0'..'9','.','/'); | |
$now=time; | |
($pert1,$pert2) = unpack("C2",$user); | |
$week = $now / (60*60*24*7) + $pert1 + $pert2; | |
$nsalt = $salt_set[$week % 64] . $salt_set[$now %64]; | |
return crypt($pass,$nsalt); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment