public static function generateCookieToken($login, $password)
 {
     $persistence = 0;
     $config = self::loadConfig();
     // Add a cookie for session persistance, if enabled
     if (isset($config['persistant_enable']) && $config['persistant_enable']) {
         if (!isset($config['persistant_crypt_key']) || !isset($config['persistant_cookie_name']) || trim($config['persistant_crypt_key']) == '' || trim($config['persistant_cookie_name']) == '') {
             jLog::log(jLocale::get('jelix~auth.error.persistant.incorrectconfig', 'persistant_cookie_name, persistant_crypt_key'), 'error');
             return 0;
         }
         if (isset($config['persistant_duration'])) {
             $persistence = intval($config['persistant_duration']) * 86400;
         } else {
             $persistence = 86400;
             // 24h
         }
         $persistence += time();
         $encrypted = jCrypt::encrypt(serialize(array($login, $password)), $config['persistant_crypt_key']);
         setcookie($config['persistant_cookie_name'] . '[auth]', $encrypted, $persistence, $config['persistant_cookie_path'], "", false, true);
     }
     return $persistence;
 }
示例#2
0
 /**
  * authentificate a user, and create a user in the php session
  * @param string $login the login of the user
  * @param string $password the password to test (not encrypted)
  * @param boolean $persistant (optional) the session must be persistant
  * @return boolean true if authentification is ok
  */
 public static function login($login, $password, $persistant = false)
 {
     $dr = self::_getDriver();
     $config = self::_getConfig();
     if ($user = $dr->verifyPassword($login, $password)) {
         $eventresp = jEvent::notify('AuthCanLogin', array('login' => $login, 'user' => $user));
         foreach ($eventresp->getResponse() as $rep) {
             if (!isset($rep['canlogin']) || $rep['canlogin'] === false) {
                 return false;
             }
         }
         $_SESSION[$config['session_name']] = $user;
         $persistence = 0;
         // Add a cookie for session persistance, if enabled
         if ($persistant && isset($config['persistant_enable']) && $config['persistant_enable']) {
             if (!isset($config['persistant_crypt_key']) || !isset($config['persistant_cookie_name'])) {
                 throw new jException('jelix~auth.error.persistant.incorrectconfig', 'persistant_cookie_name, persistant_crypt_key');
             }
             if (isset($config['persistant_duration'])) {
                 $persistence = $config['persistant_duration'] * 86400;
             } else {
                 $persistence = 86400;
             }
             // 24h
             $persistence += time();
             $encrypted = jCrypt::encrypt(serialize(array($login, $password)), $config['persistant_crypt_key']);
             setcookie($config['persistant_cookie_name'] . '[auth]', $encrypted, $persistence, $config['persistant_cookie_path']);
         }
         jEvent::notify('AuthLogin', array('login' => $login, 'persistence' => $persistence));
         return true;
     } else {
         return false;
     }
 }
示例#3
0
 public static function generateCookieToken($login, $password)
 {
     $persistence = 0;
     $config = self::loadConfig();
     // Add a cookie for session persistance, if enabled
     if (isset($config['persistant_enable']) && $config['persistant_enable']) {
         if (!isset($config['persistant_crypt_key']) || !isset($config['persistant_cookie_name'])) {
             throw new jException('jelix~auth.error.persistant.incorrectconfig', 'persistant_cookie_name, persistant_crypt_key');
         }
         if (isset($config['persistant_duration'])) {
             $persistence = $config['persistant_duration'] * 86400;
         } else {
             $persistence = 86400;
         }
         // 24h
         $persistence += time();
         //$login = $_SESSION[$config['session_name']]->login;
         $encrypted = jCrypt::encrypt(serialize(array($login, $password)), $config['persistant_crypt_key']);
         setcookie($config['persistant_cookie_name'] . '[auth]', $encrypted, $persistence, $config['persistant_cookie_path']);
     }
     return $persistence;
 }