Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP LDAP authentication NOT WORKING

Tags:

php

ldap

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";
    }
}
like image 286
Brett Avatar asked Dec 31 '25 11:12

Brett


1 Answers

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"

like image 120
Gazillion Avatar answered Jan 03 '26 00:01

Gazillion



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!