blob: ee628ec84a902b73c8d58080fd1dbdf3f2973786 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#!/usr/bin/perl -w
# OpenLDAP {APR1} to Apache $apr1$ hash converter
# (C) 2011 Devin J. Pohly
# You may use this code freely. It would be nice to be credited.
use MIME::Base64;
while (<>) {
($user, $hash) = split(/:/, $_);
unless ($hash =~ /^{APR1}/) {
print STDERR "Not an Apache MD5 hash\n";
next;
}
chomp $hash;
$hash = decode_base64(substr($hash, 6));
($hash, $salt) = (substr($hash, 0, 16), substr($hash, 16));
$hash = $hash;
$hash =~ s/(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)/$1$7$13$2$8$14$3$9$15$4$10$16$5$11$6\0\0$12/s;
$hash = encode_base64($hash);
chomp $hash;
$hash =~ s/(.)(.)(.)(.)/$4$3$2$1/gs;
unless ($hash =~ /AA$/) {
#print "Problem with hash\n";
next;
}
$hash =~ s/AA$//;
$hash =~ tr|A-Za-z0-9+/|./0-9A-Za-z|;
print "$user:\$apr1\$$salt\$$hash\n"
}
|