Hi.
After several failed attempts, I need some help regarding the following issue. I need to import some users from a MySQL database to OpenLDAP. I cannot find a working way of converting the md5 password stored in the database (using md5() ) to the {MD5} password format for Ldap.
e.g: SQL: the md5 value of 'password' is 5f4dcc3b5aa765d61d8327deb882cf99 OpenLDAP: the result of `slappasswd -h {MD5} -s password` is {MD5}X03MO1qnZdYdgyfeuILPmQ==
So obviously I won't be able to use {MD5}5f4dcc3b5aa765d61d8327deb882cf99
From what I could gather it has to do with Base64 encoding but all my
attemps at scripting something failed miserably :( Any hint would be appreciated.
Thanks!
Antoine Jacoutot wrote:
Hi.
After several failed attempts, I need some help regarding the following issue. I need to import some users from a MySQL database to OpenLDAP. I cannot find a working way of converting the md5 password stored in the database (using md5() ) to the {MD5} password format for Ldap.
e.g: SQL: the md5 value of 'password' is 5f4dcc3b5aa765d61d8327deb882cf99
Looks like a hexpair representation of a binary value. Convert it to binary and base64 encode it.
OpenLDAP: the result of `slappasswd -h {MD5} -s password` is {MD5}X03MO1qnZdYdgyfeuILPmQ==
So obviously I won't be able to use {MD5}5f4dcc3b5aa765d61d8327deb882cf99
From what I could gather it has to do with Base64 encoding but all my
attemps at scripting something failed miserably :( Any hint would be appreciated.
p.
Ing. Pierangelo Masarati OpenLDAP Core Team
SysNet s.r.l. via Dossi, 8 - 27100 Pavia - ITALIA http://www.sys-net.it --------------------------------------- Office: +39 02 23998309 Mobile: +39 333 4963172 Email: pierangelo.masarati@sys-net.it ---------------------------------------
On Fri, 18 Jan 2008, Pierangelo Masarati wrote:
Looks like a hexpair representation of a binary value. Convert it to binary and base64 encode it.
Indeed. For the archives, here's the script I used:
#-------------------------------------------# #!/usr/bin/perl use MIME::Base64; use strict; my @md5 = split "",$ARGV[0]; my @res; for (my $i = 0 ; $i < 32 ; $i+=2) { my $c = (((hex $md5[$i]) << 4) % 255) | (hex $md5[$i+1]); $res[$i/2] = chr $c; } print "{MD5}".encode_base64(join "", @res); #-------------------------------------------#
$ perl md5_sql2ldap.pl 5f4dcc3b5aa765d61d8327deb882cf99 {MD5}X03MO1qnZdYdgyfeuILPmQ==
Thanks.
openldap-technical@openldap.org