Location: PHPKode > projects > GuanxiCRM Business Solution > include/Auth/ldap.inc
<?PHP
/* $Id: ldap.inc,v 1.7 2003/01/24 14:26:18 k-fish Exp $ */
  
function authentify_user($user, $pass, $encrypted_pwd=''){
   global $appconf;
   
   $ldap = @ldap_connect($appconf["auth_ldaphost"]);
   if (!$ldap) {
      print  "Could not connect to LDAP server ";
      exit;
   };

   
   //following code from Horde project
   //Arent many ways of doing it

     if($appconf["auth_ldaptype"]==1) {
     /* Attempt to bind to the LDAP server as administrator. */
        // decrypt ldap pw from config.inc.php
		include("include/crypt.inc");
		$myC = new Crypto();
		$de_ldappw = $myC->decrypt("moregroupware", $appconf["auth_ldappasswd"]);
                
        $bind = ldap_bind($ldap, $appconf["auth_ldapuid"], $de_ldappw);
        
        if ($bind == false) {
            ldap_close($ldap);
            return true;
        }

       //do search
       $search = ldap_search($ldap, $appconf["auth_ldapbase"],
       "(samaccountname=".$user.")", 
       array("usncreated","samaccountname","dn","givenname","sn","cn"));
        $result = ldap_get_entries($ldap, $search);
        if (is_array($result) && (count($result) > 1)) {
              $dn=$user.$appconf["auth_ldapsuffixe"];
        } else {
            return false; //user not found
        }
      } else {
        /* Attempt to bind to the LDAP server as administrator. */
		
		// decrypt ldap pw from config.inc.php
		include("include/crypt.inc");
		$myC = new Crypto();
		$de_ldappw = $myC->decrypt("moregroupware", $appconf["auth_ldappasswd"]);
		$bind = ldap_bind($ldap, $appconf["auth_ldapuid"], $de_ldappw);

        if ($bind == false) {
            ldap_close($ldap);
            return true;
        }

       //do search
       $search = ldap_search($ldap, $appconf["auth_ldapbase"],
       "(uid=".$user.")", 
       array("usncreated","samaccountname","dn","givenname","sn","cn"));
        $result = ldap_get_entries($ldap, $search);
        if (is_array($result) && (count($result) > 1)) {
              $dn=$result[0]["dn"];
        } else {
            return false; //user not found
        }
      
      
      }
        /* Attempt to bind to the LDAP server as the user. */
        if ($pass=="") { $pass="foo_moregroupware"; }
        $bind = ldap_bind($ldap, $dn, $pass);

        if ($bind != false) {
            ldap_close($ldap);
            return true;
        }
        @ldap_close($ldap);
        return false;
}
?>
Return current item: GuanxiCRM Business Solution