/**
  * Tries to authenticate the current request
  * @return bool Returns if the authentication was successful
  */
 public function authenticate()
 {
     $username = NULL;
     $password = NULL;
     // mod_php
     if (isset($_SERVER['PHP_AUTH_USER'])) {
         $username = $_SERVER['PHP_AUTH_USER'];
         $password = $_SERVER['PHP_AUTH_PW'];
         // most other servers
     } elseif (isset($_SERVER['HTTP_AUTHENTICATION'])) {
         if (strpos(strtolower($_SERVER['HTTP_AUTHENTICATION']), 'basic') === 0) {
             list($username, $password) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHENTICATION'], 6)));
         }
     }
     return $this->userProvider->checkCredentials($username, $password);
 }
Example #2
0
 /**
  * @test
  */
 public function checkCredentialsForFutureUserTest()
 {
     $this->assertFalse($this->fixture->checkCredentials('future_user', 'myApiKey'));
     $this->assertFalse($this->fixture->checkCredentials('future_user', 'wrongKey'));
     $this->assertFalse($this->fixture->checkCredentials('future_user', ''));
     $this->assertFalse($this->fixture->checkCredentials('future_user', NULL));
 }
Example #3
0
 /**
  * Check the given login data
  *
  * @param array $sentData
  * @return array
  */
 public function checkLogin($sentData)
 {
     $loginStatus = self::STATUS_LOGGED_OUT;
     if (isset($sentData['username']) && isset($sentData['apikey'])) {
         $username = $sentData['username'];
         $apikey = $sentData['apikey'];
         if ($this->userProvider->checkCredentials($username, $apikey)) {
             $loginStatus = self::STATUS_LOGGED_IN;
         } else {
             $loginStatus = self::STATUS_FAILURE;
         }
         $this->sessionManager->setValueForKey('loginStatus', $loginStatus);
     }
     return array('status' => $loginStatus);
 }