tags:

views:

44

answers:

1

How can I reset a LDAP password in PHP?
I already have a connection to the LDAP Server.

+1  A: 

Try the following code:

$dn = "uid=".$username.",dc=example,dc=com";
$newPassword = ...;
$newEntry = array('userpassword' => "{MD5}".base64_encode(pack("H*",md5($newPassword))));

if(ldap_mod_replace($ldapConnection, $dn, $newEntry))
    print "<p>succeded</p>";
else
    print "<p>failed</p>";

See:

http://php.net/manual/en/function.ldap-mod-replace.php

http://logout.sh/computers/ldap/

Steven Paligo
Is it always the same way to decrypt the password?
Eragonio
I'm not sure I understand what you're asking.
Steven Paligo
Sorry, I mean to encrypt the password. You encrypt it with md5 and then with base64.
Eragonio
Actually there are at least five different password hashing schemes (speaking for OpenLDAP): `{CRYPT}`, `{MD5}`. `{SMD5}`. `{SHA}`, `{SSHA}`. See http://www.openldap.org/faq/data/cache/347.html, http://www.openldap.org/faq/data/cache/418.html, http://www.openldap.org/faq/data/cache/344.html
Stefan Gehrig