Since there’s not so much documentation online, I had to struggle a bit to get LDAP working.. but here’s the code 🙂 Hopefully it’ll help some other people.
Of course, there are better ways to get this running, but that’s my quick fix.
File: application/Default/Controllers/LoginController.php
Change the line $success = Phprojekt_Auth::login($username, $password, $keepLogged); to this
try {
function tryLdap($username,$pass) {
//Try the ldap thing
if (strlen(‘cisolve.local’) != 0) {
$username = $username . ‘@’ . ‘mydomain.local’;
}
$ldapconn = ldap_connect(‘ldap://’ . ‘xxx.xxx.xxx.xxx’); // 2
if (!$ldapconn) {
die(‘Cannot connect to server’);
return false;
}
$ldap_secure_connection = ‘no’; // 3
if ($ldap_secure_connection == ‘tls’) {
if (!ldap_start_tls($ldapconn)) {
ldap_close($ldapconn);
die(‘Cannot connect securely to server’);
return false;
}
}
$ldapbind = ldap_bind($ldapconn, $username, $pass);
ldap_close($ldapconn);
if ($ldapbind) {
return true;
} else {
return false;
}
}
$ldapSuccess = tryLdap($username,$password);
if($ldapSuccess==true) {
$success = Phprojekt_Auth::login($username, $keepLogged);
} else {
$success=false;
throw new Phprojekt_Auth_Exception(‘Invalid user or password’, 1);
}
File: library/Phprojekt/Auth.php
Change line
public static function login($username, $password, $keepLogged = false)
to
public static function login($username, $keepLogged = false)
In the same file,
comment-out the following:
// The password does not match with password provided
/* if (!Phprojekt_Auth::_compareStringWithPassword($password, $setting->getSetting(“password”, $userId))) {
throw new Phprojekt_Auth_Exception(‘Invalid user or password’, 2);
} */
That should do the trick. Do not forget to change the values from the LoginController.php to reflect your domain settings.
Read More