PHP LDAP Connection

I am trying to connect to LDAP with php-ldap. I have a problem with ldap_bind() :

 $username = 'josue.ruiz'; $password = 'pass'; $ldapconfig['host'] = '10.10.10.11'; $ldapconfig['port'] = 389; $ldapconfig['basedn'] = 'dc=domain,dc=com'; $ds=ldap_connect($ldapconfig['host'], $ldapconfig['port']); ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($ds, LDAP_OPT_REFERRALS, 0); $dn="cn=".$username.",ou=Technology,".$ldapconfig['basedn']; if ($bind=ldap_bind($ds, $dn, $password)) { echo("Login correct"); } else { echo("Login incorrect"); } 

I get this message:

Warning: ldap_bind (): cannot bind to server: invalid credentials in ...

But when I try like this:

 ldap_bind($ds,' josue.ruiz@domain.com ','pass'); 

It works fine, but it doesnโ€™t work for me, because I want to filter OU , and I cannot do this. Does anyone have any tips on this issue?

+4
source share
1 answer

When you try to execute ldap_bind , you only connect and determine if the credentials are checked. What you need to do is add your domain to the username and allow it to connect. Then, if you want to determine if the user is a โ€œtechnologyโ€ unit with ldap_search() , consider this:

 $domain = 'mydomain.com'; $username = 'josue.ruiz'; $password = 'pass'; $ldapconfig['host'] = '10.10.10.11'; $ldapconfig['port'] = 389; $ldapconfig['basedn'] = 'dc=domain,dc=com'; $ds=ldap_connect($ldapconfig['host'], $ldapconfig['port']); ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($ds, LDAP_OPT_REFERRALS, 0); $dn="ou=Technology,".$ldapconfig['basedn']; $bind=ldap_bind($ds, $username .'@' .$domain, $password); $isITuser = ldap_search($bind,$dn,'(&(objectClass=User)(sAMAccountName=' . $username. '))'); if ($isITuser) { echo("Login correct"); } else { echo("Login incorrect"); } 
+6
source

Source: https://habr.com/ru/post/1395823/


All Articles