Perl‎ > ‎

htpasswd

Generate htpasswd using perl

#!/usr/bin/perl -w
# vim: nosta noet nospell sw=4 ts=4

use strict;
use Data::Dumper;
$Data::Dumper::Deepcopy = 1; $Data::Dumper::Indent = 1;
$Data::Dumper::Useqq = 1; $Data::Dumper::Quotekeys = 0;
sub d { warn Data::Dumper->Dump( [$_[0]], [$_[1]] ); }

my $top = '/usr/home/v2.hannity.com/htdocs/rss/iHxja13y7oXtBcbQDGRJ3Lk4Z9pNmzMSCinsider/';

chdir $top;

my $salt;
sub processLine
{
my $line = shift;
$salt = substr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", rand length("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"), 1);
$salt .= substr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", rand length("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"), 1);
my ($user, $pass) = split /:/, $line;
$pass = crypt $pass, $salt;
print OUT "$user:$pass\n";
}

open OUT, '>htpasswd.tmp' or die "htpasswd.tmp: $!\n";
while( <> ) {
s/\r|\n//g;
processLine($_);
}
close OUT;

rename 'htpasswd.tmp', '.htpasswd' or die "mv htpasswd.tmp .htpasswd: $!\n";


Comments