3 # Apache $apr1$ to OpenLDAP {APR1} hash converter
\r
4 # (C) 2011 Devin J. Pohly
\r
5 # You may use this code freely. It would be nice to be credited.
\r
10 ($user, $hash) = split(/:/, $_);
\r
11 unless ($hash =~ /^\$apr1\$/) {
\r
12 print STDERR "Not an Apache MD5 hash\n";
\r
17 ($_,$_,$salt,$hash) = split(/\$/, $hash);
\r
19 $hash =~ tr|./0-9A-Za-z|A-Za-z0-9+/|;
\r
21 $hash =~ s/(.)(.)(.)(.)/$4$3$2$1/gs;
\r
22 $hash = decode_base64($hash);
\r
23 $hash =~ s/(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)..(.)/$1$4$7$10$13$15$2$5$8$11$14$16$3$6$9$12/s;
\r
25 $hash = encode_base64($hash);
\r
28 print "$user:{APR1}$hash\n";
\r