diff --git a/auth/ldap/lib.php b/auth/ldap/lib.php index b0eb9e4..f5c7b47 100644 --- a/auth/ldap/lib.php +++ b/auth/ldap/lib.php @@ -1000,6 +1000,22 @@ function auth_user_update_password($user . ldap_err2str(ldap_errno($ldapconnection))); } break; + case 'ad': + // Passwords in Active Directory must be encoded as Unicode + // strings (UCS-2 Little Endian format) and surrounded with + // double quotes. See http://support.microsoft.com/?kbid=269190 + if (!function_exists('mb_convert_encoding')) { + error_log ('You need the mbstring extension to change passwords in Active Directory'); + return false; + } + $newpassword = mb_convert_encoding('"'.$newpassword.'"', "UCS-2LE", "auto"); + $result = ldap_modify($ldapconnection, $user_dn, array('unicodePwd' => $newpassword)); + if(!$result){ + error_log('LDAP Error in auth_user_update_password(). Error code: ' + . ldap_errno($ldapconnection) . '; Error string : ' + . ldap_err2str(ldap_errno($ldapconnection))); + } + break; default: $usedconnection = &$ldapconnection; // send ldap the password in cleartext, it will md5 it itself