1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
public function authentifie($user='',$pass='') {
if(empty($pass)) throw new Exception("Mot de passe obligatoire");
$user="cn=".$user;
$nom='';
$domaine="ou=info,ou=md1,o=orga";
// connexion
$ds=ldap_connect("xx.xx.xx.xx:389");
if(!$ds) throw new Exception ("Connexion LDAP impossible");
// setting
$vs = ldap_set_option($ds,LDAP_OPT_PROTOCOL_VERSION, 3);
if(!$vs) throw new Exception ("Impossible de modifier la version de protocole du serveur LDAP");
$vs = ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
if(!$vs) throw new Exception ("Impossible de modifier la version referrals du serveur LDAP");
// recherche
$read=ldap_search($ds,$domaine,$user);
if(!$read) throw new Exception("recherche impossible");
// recuperation des donnees
$info=ldap_get_entries($ds,$read);
$dn=$info[0]['dn'];
if(empty($dn)) throw new Exception("Utilisateur non trouvé");
$rep=$info[0]['fullname'];
$nom=$rep[0];
$cn=ldap_bind($ds,$dn,$pass);
if(!$cn) throw new Exception ("Mot de passe invalide");
// fermeture
if(! ldap_close($ds)) throw new Exception ("Echec de fermeture connexion LDAP");
return $nom;
} |
Partager