Código :
<?php
// using ldap bind
$ldaprdn = 'cn=admin,dc=servidor;
$ldappass = 'secreto';
// connect to ldap server
$ldapconn = ldap_connect("127.0.0.1")
or die("No hay conexión con el servidor de autenticación.");
if ($ldapconn) {
// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
// verify binding
if ($ldapbind) {
$person = "xyrer";
$password = "password";
$dn = "dc=servidor";
$sr = ldap_search($ldapconn,$dn,'uid='.$person);
if ($sr)
{
//echo "funciona la busqueda<br />";
$ldapinfo = ldap_get_entries( $ldapconn, $sr );
} else {
echo "Error de busqueda";
}
if ($ldapinfo)
{
$clave = $ldapinfo[0]["userpassword"][0];
$clave2 = "{MD5}".base64_encode(pack("H*",md5($password)));
if ($clave == $clave2")
{
$output = "loginsuccess";
$newpwd = "nuevaclave";
$cn = $ldapinfo[0]['cn'];
$info['userPassword'] = "{MD5}".base64_encode(pack("H*",md5($newpwd)));
if (ldap_mod_replace ($ldapconn, $cn, $info))
{
echo "<loginsuccess>Clave cambiada</loginsuccess>";
} else {
echo "<loginsuccess>Falló el procedimiento</loginsuccess>";
}
} else {
$output = "Acceso Denegado";
}
echo ($output);
print_r($ldapinfo);
echo "<br /><br /><br />";
echo "Nombre real: ".$ldapinfo[0]["cn"][0]."<br />";
echo "Usuario: ".$ldapinfo[0]["uid"][0]."<br />";
echo "password: ".$ldapinfo[0]["userpassword"][0]."<br />";
} else {echo "Error de ldapinfo";}
} else {
echo "Error de bind";
}
ldap_close($ldapconn);
} else {
echo "Error de conexion";
}
?> 