Skip to content

Instantly share code, notes, and snippets.

@jhargis
Created August 29, 2013 04:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhargis/6374306 to your computer and use it in GitHub Desktop.
Save jhargis/6374306 to your computer and use it in GitHub Desktop.
generate an htpasswd with perl script
#!/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