I have the following code to authenticate users from php against the ldap directory.
$ldap_host = "10.1.24.3"; // nombre del host o servidor
$ldap_port = 389; // puerto del LDAP en el servidor
$ldap_dn = 'cn=admin,dc=pinarx,dc=pri,dc=jovenclub,dc=cu';
$ldap_pass_user = 'ldapadmin';
// conexion a ldap
$ldap_conn = ldap_connect( $ldap_host, $ldap_port );
ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
$ldap_bind = ldap_bind( $ldap_conn, $ldap_dn, $ldap_pass_user );
if ($ldap_bind){
//realizo la busquedad
$filtro="(&(uid=$login_user)(userpassword=$pass_user))";
$solonecesito = array( "uid");
$sr=ldap_search($ldap_conn,"dc=pinarx,dc=pri,dc=jovenclub,dc=cu", $filtro, $solonecesito);
$info = ldap_get_entries($ldap_conn, $sr);
for ($i=0; $i<$info["count"]; $i++){
$_SESSION['login_user'] = $info[$i]["uid"][0] ."";
}
}
The problem that arises is that in the filter that I set, it does not work for me, and I want it to do is to look for the user exactly by his login and password, if I remove the password filter, it works fine, but then I do not validate that the user's password is correct, so in addition to the login I want you to check that the password is correct.
Could someone tell me what I have wrong or what I have to add?