* @package Mammut\Auth */ class Basic extends Base { public function __construct(iAuthClient $handler, $realm) { parent::__construct($handler, $realm); } public function isAuthenticated() { if(!isset($_SERVER['PHP_AUTH_USER'])) return false; $handler = $this->getHandler(); return $handler->isUserSecretValid($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); } public function getUser() { if(!$this->isAuthenticated()) return NULL; return isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : NULL; } public function authenticate() { if($this->isAuthenticated()) return true; $realm = $this->getRealm(); header("WWW-Authenticate: Basic realm=\"{$realm}\""); header('HTTP/1.0 401 Unauthorized'); return false; } }