This class has the ability to authenticate against LDAP and Active Directory. It also has the ability to perform searches against LDAP and AD to pull information from the LDAP and AD Schema.
PHP Example :
<?PHP
class ldap
{
var $ldapConn; //ldap connection storage variable
var $ldapBind; //ldap bind storage variable
var $entries; //ldap entries variable
var $ldapLookupUser;
var $ldapLookupPass;
var $server;
var $port;
var $by;
var $search;
var $baseDN;
function ldap($server,$port,$baseDN)
{
$this->server=$server;
$this->port=$port;
$this->baseDN=$baseDN;
}
function ldapConn()
{
$this->ldapConn = @ldap_connect($this->server,$this->port);
return $this->ldapConn;
}
function ldapBind($ldapLookupUser,$ldapLookupPass)
{
if(@ldap_bind($this->ldapConn,$ldapLookupUser,$ldapLookupPass))
{
$this->ldapBind = @ldap_bind($this->ldapconn,$ldapLookupUser,$ldapLookupPass);
return true;
}
else
return false;
}
function ldapAuthenticate($usrname,$password)
{
if(@ldap_bind($this->ldapConn,$usrname,$password))
return true;
else
return false;
}
function ldapSearch($by,$search,$ous,$searchby)
{
$c=0;
foreach($ous as $ou)
{
$read=ldap_search($this->ldapConn,"ou=$ou,$this->baseDN", "$searchby=*$search*");
$entries = ldap_get_entries($this->ldapConn, $read);
for ($i=0; $i<$entries["count"]; $i++)
{
if($entries[$i][$by][0])
$values[$c]=$entries[$i][$by][0];
$c++;
}
}
return $values;
}
}
?>