如何在PHP中重置LDAP密码?
我已经连接到LDAP服务器。
答案 0 :(得分:6)
请尝试以下代码:
$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>";
请参阅:
答案 1 :(得分:0)
在寻找解决方案时,我经历了很多次……使用Symfony 5.1对我有用:
# app/config/packages/security.yaml
services:
Symfony\Component\Ldap\Ldap:
arguments: ['@Symfony\Component\Ldap\Adapter\ExtLdap\Adapter']
Symfony\Component\Ldap\Adapter\ExtLdap\Adapter:
arguments:
- host: ADServerIP
port: 636
encryption: ssl
debug: true
options:
protocol_version: 3
referrals: false
然后更改密码:
// Inject this
Symfony\Component\Ldap\Ldap $ldap ;
// Connect as superadmin
$ldap->bind('CN=Admin,CN=Users,DC=ADRMTW,DC=NET', 'adminN1cePassword');
$username = 'john.doe';
$newPassword = 'azerty!123';
$userPassword = mb_convert_encoding('"'.$newPassword.'"', 'utf-16le');
$query = $ldap->query('OU=client,DC=ADRMTW,DC=NET', "(&(objectclass=person)(sAMAccountName=$username))");
$result = $query->execute()->toArray();
$entry = $result[0];
$newEntry = new Entry($entry->getDn(), [
'unicodePwd' => [$password],
]);
$ldap->getEntryManager()->update($newEntry);