<?php
$ds = ldap_connect("localhost"); // assuming the LDAP server is on this host
if ($ds) {
// bind with appropriate dn to give update access
$bind = ldap_bind($ds, "cn=root, o=My Company, c=US", "secret");
if (!$bind) {
echo "Unable to bind to LDAP server";
exit;
}
// use PASSWD EXOP to change the user password for a generated one
$genpw = ldap_exop_passwd($ds, "cn=root, o=My Company, c=US", "secret");
if ($genpw) {
// use the generated password to bind
$bind = ldap_bind($ds, "cn=root, o=My Company, c=US", $genpw);
}
// set the password back to "secret"
ldap_exop_passwd($ds, "cn=root, o=My Company, c=US", $genpw, "secret");
ldap_close($ds);
} else {
echo "Unable to connect to LDAP server";
}
?>