Guest User

Untitled

a guest
Dec 24th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.98 KB | None | 0 0
  1.     public function processLoginAction ()
  2.     {
  3.         $username = "DOMAIN\\".$this->_getParam('user');
  4.         $password = $this->_getParam('password');
  5.        
  6.         $ldap_auth_result = $this->ldap_auth_handler($username, $password, "ldap");
  7.         echo $ldap_auth_result;
  8.        
  9.         //TODO: Use result to set cookie or send out failure notices.
  10.    }
  11.    
  12.    private function ldap_auth_handler($user, $pass){
  13.         set_time_limit(250); //tell php it's okay to run longer than normal
  14.         $ldap_curr = 1;
  15.         $ldap_max = 3;
  16.        
  17.         /**
  18.          * Loop until we've tried all 3 ldap servers.
  19.          * If a server provides a success/fail login msg, stop the loop
  20.          *
  21.          */
  22.         while ($ldap_curr <= $ldap_max) {
  23.             $ldap_auth_response = $this->ldap_auth($user, $pass, "ldap".$ldap_curr);
  24.             if ($ldap_auth_response == "LDAP_Error" && $ldap_curr != $ldap_max){
  25.                 $ldap_curr++;
  26.             } else if ($ldap_auth_response == "LDAP_Error" && $ldap_curr == $ldap_max){
  27.                 return "LDAP_Error Max";
  28.             } else if ($ldap_auth_response == "SUCCESS"){
  29.                 return "Success".$ldap_curr;
  30.                 $ldap = $ldap_max;
  31.             } else if ($ldap_auth_response == "FAIL"){
  32.                 return "Failure".$ldap_curr;
  33.                 $ldap = $ldap_max;
  34.             }
  35.         }
  36.    }
  37.    
  38.    private function ldap_auth($user, $pass, $ldap_server){
  39.         $config = new Zend_Config_Ini(
  40.         'C:\ZendServer\Apache2\htdocs\hub\application\configs\application.ini',
  41.         'production');
  42.         $options = $config->$ldap_server->toArray();
  43.         $adapter = new Zend_Auth_Adapter_Ldap($options, $user, $pass);
  44.         $auth = Zend_Auth::getInstance();
  45.         $result = $auth->authenticate($adapter);
  46.        
  47.         $messages = $result->getMessages();
  48.         $success = $messages[3];
  49.        
  50.         if (preg_match("/successful/i", $success)){
  51.             return "SUCCESS";
  52.         } elseif (preg_match("/failed/i", $success)){
  53.             return "FAIL";
  54.         } else {
  55.             return "LDAP_Error";
  56.         }
  57.    }
Add Comment
Please, Sign In to add comment