3

I am trying to implement LDAP authentication into our company web portal. I can successfully connect to the host, but I cannot seem to get a successful bind with my Active Directory credentials. Looking for some help on what could possibly be going wrong. Any help, tips, or advice would be greatly appreciated.

$username = $_POST['username'];
$password = $_POST['password'];

$host = "xxx.xxx.xxx.xxx";
$port = "389";

$connection = ldap_connect($host, $port) or die("Could not connect to LDAP server.");
ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);

if ($connection) {
    $bind = ldap_bind($connection, $username, $password);
    if ($bind) {
         echo "LDAP bind successful";
    } 
    else {
         echo "LDAP bind failed";
    }
}
1
  • 1
    Have you checked logs? Any errors, whats NOT working? Also are you using the login DOMAIN\USERNAME ? Commented Sep 15, 2011 at 18:08

1 Answer 1

6

I had the same problem recently enough and the solution was to add the domain to the username.

$isAuth = ldap_bind($ldap_conn,$_POST['username'].$ldap_settings['adDomain'], $_POST['password']);

Where $ldap_settings['adDomain'] was "@your_domain"

Sign up to request clarification or add additional context in comments.

2 Comments

This was the solution. I had a feeling I would need the domain, but in the examples I researched, I hadn't seen the domain appended to the username. Thanks for the prompt help!
DOMAIN WITHOUT .COM/.NET or whatever :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.