Outils pour utilisateurs

Outils du site


php:authentification_ldap_objet

authentification method objet avec un ldap /active directory


class ad
{
	public function __construct(){
		include './config/config.php';
		$this->_host=$host_ldap;
		$this->_domain=$domain_ldap;
		$this->_ldap = ldap_connect($this->_host);
	}

	public function connect($user, $password){
		$ldaprdn = $this->_domain . "\\" . $user;
	    ldap_set_option($this->_ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
	    ldap_set_option($this->_ldap, LDAP_OPT_REFERRALS, 0);
	    $bind = @ldap_bind($this->_ldap, $ldaprdn, $password);
	    return $bind;
	}

	public function login($user, $password){
		$bind=$this->connect($user,$password);
	    if ($bind) {
	    	return 1;
	    }else{
	    	return 0;
	    }
	}
	public function get_info($user, $password){
		$bind=$this->connect($user,$password);
		if ($bind) {
	        $filter="(sAMAccountName=$user)";
	        $result = ldap_search($this->_ldap,"dc=DOM2003,dc=local",$filter);
	        ldap_sort($this->_ldap,$result,"sn");
	        $info = ldap_get_entries($this->_ldap, $result);
	        for ($i=0; $i<$info["count"]; $i++)
	        {
	            if($info['count'] > 1)
	                break;
	            echo "<p>You are accessing <strong> ". $info[$i]["sn"][0] .", " . $info[$i]["givenname"][0] ."</strong><br /> (" . $info[$i]["samaccountname"][0] .")</p>\n";
	            echo '<pre>';
	            var_dump($info);
	            echo '</pre>';
	            $userDn = $info[$i]["distinguishedname"][0]; 
	        }
	        @ldap_close($ldap);
	    } else {
	        $msg = "Invalid email address / password";
	        echo $msg;
	    }
	}
}

php/authentification_ldap_objet.txt · Dernière modification: 2019/01/25 15:56 (modification externe)