Пример #1
0
 /**
  * Gets and sets the RememberMe class
  *
  * @param  mixed $var A rememberMe instance to set
  *
  * @return RememberMe\RememberMe Returns the current rememberMe instance
  */
 public function rememberMe($var = null)
 {
     if ($var !== null) {
         $this->rememberMe = $var;
     }
     if (!$this->rememberMe) {
         /** @var Config $config */
         $config = $this->grav['config'];
         // Setup storage for RememberMe cookies
         $storage = new RememberMe\TokenStorage();
         $this->rememberMe = new RememberMe\RememberMe($storage);
         $this->rememberMe->setCookieName($config->get('plugins.login.rememberme.name'));
         $this->rememberMe->setExpireTime($config->get('plugins.login.rememberme.timeout'));
         // Hardening cookies with user-agent and random salt or
         // fallback to use system based cache key
         $server_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'unknown';
         $data = $server_agent . $config->get('security.salt', $this->grav['cache']->getKey());
         $this->rememberMe->setSalt(hash('sha512', $data));
         // Set cookie with correct base path of Grav install
         $cookie = new Cookie();
         $cookie->setPath($this->grav['base_url_relative']);
         $this->rememberMe->setCookie($cookie);
     }
     return $this->rememberMe;
 }
Пример #2
0
 /**
  * Gets and sets the RememberMe class
  *
  * @param  mixed            $var    A rememberMe instance to set
  *
  * @return Authenticator            Returns the current rememberMe instance
  */
 public function rememberMe($var = null)
 {
     if ($var !== null) {
         $this->rememberMe = $var;
     }
     if (!$this->rememberMe) {
         /** @var Config $config */
         $config = $this->grav['config'];
         // Setup storage for RememberMe cookies
         $storage = new RememberMe\TokenStorage();
         $this->rememberMe = new RememberMe\RememberMe($storage);
         $this->rememberMe->setCookieName($config->get('plugins.login.rememberme.name'));
         $this->rememberMe->setExpireTime($config->get('plugins.login.rememberme.timeout'));
         // Hardening cookies with user-agent and system based cache key
         $data = $_SERVER['HTTP_USER_AGENT'] . $this->grav['cache']->getKey();
         $this->rememberMe->setSalt(password_hash($data, PASSWORD_DEFAULT));
         // Set cookie with correct base path of Grav install
         $cookie = new Cookie();
         $cookie->setPath($this->grav['base_url_relative']);
         $this->rememberMe->setCookie($cookie);
     }
     return $this->rememberMe;
 }
Пример #3
0
 /**
  * Gets and sets the RememberMe class
  *
  * @param  mixed            $var    A rememberMe instance to set
  *
  * @return Authenticator            Returns the current rememberMe instance
  */
 public function rememberMe($var = null)
 {
     if ($var !== null) {
         $this->rememberMe = $var;
     }
     if (!$this->rememberMe) {
         /** @var Config $config */
         $config = $this->grav['config'];
         // Setup storage for RememberMe cookies
         $storage = new RememberMe\TokenStorage();
         $this->rememberMe = new RememberMe\RememberMe($storage);
         $this->rememberMe->setCookieName($config->get('plugins.login.rememberme.name'));
         $this->rememberMe->setExpireTime($config->get('plugins.login.rememberme.timeout'));
         // Secure cookies with system based hash
         $hash = $config->get('system.security.default_hash');
         $this->rememberMe->setSalt($hash);
         // Set cookie with correct base path of Grav install
         $cookie = new Cookie();
         $cookie->setPath($this->grav['base_url_relative']);
         $this->rememberMe->setCookie($cookie);
     }
     return $this->rememberMe;
 }