Advertisement
fahmihilmansyah

ldap

Dec 5th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. <?php
  2. class Myldap {
  3.     public $err_msg = "";
  4.    
  5.  
  6.     function connect($servername, $ldap_port)
  7.     {
  8.         $ds = @ldap_connect($servername,$ldap_port);  // must be a valid LDAP server!
  9.         return $ds;
  10.     }
  11.    
  12.     function bind($ds,$rdn,$pwd)
  13.     {
  14.         if (!$ds)
  15.             return FALSE;
  16.         $r = @ldap_bind($ds,$rdn,$pwd);
  17.         return $r;
  18.     }
  19.    
  20.     function close($ds)
  21.     {
  22.         @ldap_close($ds);
  23.     }
  24.    
  25.     function set_error($err_str)
  26.     {
  27.         $this->err_msg = $err_str;
  28.     }
  29.    
  30.     function clear_error()
  31.     {
  32.         $this->err_msg = '';
  33.     }
  34.    
  35.     function get_last_error()
  36.     {
  37.         return $this->err_msg;
  38.     }
  39.    
  40.     function authenticate($ds,$rdn,$pwd,$port='389')
  41.     {
  42.         $ldap_con = $this->connect($ds,$port);
  43.         if ($ldap_con == FALSE)
  44.         {
  45.             return ldap_error($ldap_con);
  46.         }
  47.         $ldap_bind = $this->bind($ldap_con,$rdn,$pwd);
  48.         if ($ldap_bind == FALSE)
  49.         {
  50.             return ldap_error($ldap_con);
  51.         }
  52.         $this->close($ldap_con);
  53.         return "Login Success";
  54.     }
  55.    
  56.    
  57. }
  58. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement