Query with ldap filter from php

0

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?

    
asked by Ariochy Castiñeira Pilotos 23.01.2018 в 15:32
source

1 answer

0

I have checked the code by replacing the USERPASSWORD attribute with another one and it works correctly, but I can not make it function with the userpassword field, I pass it to the encrypted query with the same ldap function, and it does not work for me, it has not what should be done I did it this way:

$clave=md5($pass_user);
$filtro="(&(uid=$login_user)(userpassword=$clave))";
    
answered by 23.01.2018 в 16:57