Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function processLoginAction ()
- {
- $username = "DOMAIN\\".$this->_getParam('user');
- $password = $this->_getParam('password');
- $ldap_auth_result = $this->ldap_auth_handler($username, $password, "ldap");
- echo $ldap_auth_result;
- //TODO: Use result to set cookie or send out failure notices.
- }
- private function ldap_auth_handler($user, $pass){
- set_time_limit(250); //tell php it's okay to run longer than normal
- $ldap_curr = 1;
- $ldap_max = 3;
- /**
- * Loop until we've tried all 3 ldap servers.
- * If a server provides a success/fail login msg, stop the loop
- *
- */
- while ($ldap_curr <= $ldap_max) {
- $ldap_auth_response = $this->ldap_auth($user, $pass, "ldap".$ldap_curr);
- if ($ldap_auth_response == "LDAP_Error" && $ldap_curr != $ldap_max){
- $ldap_curr++;
- } else if ($ldap_auth_response == "LDAP_Error" && $ldap_curr == $ldap_max){
- return "LDAP_Error Max";
- } else if ($ldap_auth_response == "SUCCESS"){
- return "Success".$ldap_curr;
- $ldap = $ldap_max;
- } else if ($ldap_auth_response == "FAIL"){
- return "Failure".$ldap_curr;
- $ldap = $ldap_max;
- }
- }
- }
- private function ldap_auth($user, $pass, $ldap_server){
- $config = new Zend_Config_Ini(
- 'C:\ZendServer\Apache2\htdocs\hub\application\configs\application.ini',
- 'production');
- $options = $config->$ldap_server->toArray();
- $adapter = new Zend_Auth_Adapter_Ldap($options, $user, $pass);
- $auth = Zend_Auth::getInstance();
- $result = $auth->authenticate($adapter);
- $messages = $result->getMessages();
- $success = $messages[3];
- if (preg_match("/successful/i", $success)){
- return "SUCCESS";
- } elseif (preg_match("/failed/i", $success)){
- return "FAIL";
- } else {
- return "LDAP_Error";
- }
- }
Add Comment
Please, Sign In to add comment