Check username and password vie ldap php

I am trying to connect to my AD server and check if the username and password are correct, when I try it it always tells me:

Unable to bind to server: Invalid credentials

My code:

$ldapconn = ldap_connect($adserver,$adport);
$ldapbind = @ldap_bind($ldapconn,"$username","$password");

      

When I tried to set username with and without domain name in these options: user@domain.co.il domain \ user User

When I try to link anonymously, that's ok. Do you have any suggestions here?

+2


a source to share


2 answers


Check your username. It must be properly formatted RDN / DN. Special characters must be escaped.



It will help if you post a value $username

.

0


a source


If you are using Active Directory, you must set the following parameters:

ldap_set_option ($ ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);

ldap_set_option ($ ldapconn, LDAP_OPT_REFERRALS, 0);



and use FULL DN (e.g. uid = UserName, cn = Peoples, dc = example, dc = com) or short version ( UserName@example.com ). AD supports both types.

+1


a source







All Articles