PHP ldap_bind() authentication – error Unable to bind to server: Invalid credentials

ldapPHP

I'm trying to authenticate a user with LDAP using PHP. I have the DN for the user which I have checked to be correct. I also have a password. This is the correct password for the user when they authenticate with SamAccountName.

I am hoping this is the password to use when authenticating with the DN. There isn't a Distinguished Name specific password for LDAP is there? The following is my code to authenticate using PHP's ldap_bind() function. Am I doing this correct?

$ldaphost="ldap://somehost.com:3268";
$dn = "cn=LastName\, FirstName Dept/Country/ext,OU=Accounts,OU=Location,ou=Division,";
$basedn="dc=abc,dc=enterprise";

if (!($connect = ldap_connect($ldaphost))) {    
  die ("Could not connect to LDAP server"); 
} 

$ldapbind = ldap_bind($connect, "$dn" . "$basedn", $password);

if ($ldapbind) {
   echo "LDAP bind successful...";
} else {
   echo "LDAP bind failed...";
}

The result I get from the above code is :

Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server:
Invalid credentials LDAP bind failed…

From the line where ldap_bind() call is made:

$ldapbind = ldap_bind($connect, "$dn" . "$basedn", $password);

Invalid credentials makes me believe there is something wrong potentially with the DN or password. I have triple checked the DN and there is not an error there as far as I can see.

Any ideas?

Best Answer

I guess you are connecting to a Microsoft Domain, you can try the domain syntax for the credentials then. For User015 in DOMAIN - DOMAIN\user015

Related Topic