in reply to Perl and Apache Configuration Files

Just to throw my two bits into the ring, the following is a piece of code that I have used for just what you ask, generating username and password entries for htpasswd files - I think I lifted this code originally from the first edition of Learning Perl.

#!/usr/bin/perl -Tw use strict; @salt = ('a' .. 'z', 'A' .. 'Z', '0' .. '9', '.', '/'); my ($username, $password) = @ARGV; my $now = time; my ($pert1, $pert2) = unpack("C2", $username); my $salt = $salt[($now / 604800 + $pert1 + $pert2) % 64] . $salt[$now +% 64]; $password = crypt($password, $salt); print STDOUT "$username:$password\n"; exit 0;

The salt for encryption in this case is based upon the first two characters of the username and the current system time.

 

perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'