ldap_mod_replace() [function.ldap-mod-replace]: Modify: Server is unwilling to perform

安稳与你 提交于 2019-11-29 07:19:33

There are a number of things you need to get exactly right to set a password in AD via LDAP.

  • you need to use an SSL connection (ldaps://)

  • the password needs to be enclosed in quotes

  • the (quoted) password needs to be encoded in 16-bit unicode (UTF-16LE)

Assuming the password you're trying to set is ordinary ascii characters, the unicode conversion can be accomplished by adding a \000 byte after each byte of the ascii string, as shown in this code sample.

So your example would instead look like:

$newpassword = "asdf1234";
$newpassword = "\"" . $newpassword . "\"";
$len = strlen($newpassword);
for ($i = 0; $i < $len; $i++) $newpass .= "{$newpassword{$i}}\000";
$user["unicodePwd"] = $newpass;
Manish

After searching a lot and spending a lot of time, I am finally able to modify the active directory user password from PHP code using LDAP library.

We need the LDAP's connection with the active directory server from the PHP code; and that you have to modify the unicodePwd field.

ldap_connect(ldaps://IP, 636);
ldap_connect(ldaps://IP, 389);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!