示例#1
0
文件: MCrypt.php 项目: dafik/dfi
 private static function loadConfig()
 {
     if (null == self::$cipher || null == self::$secretKey || null == self::$mode) {
         self::$cipher = MCRYPT_TRIPLEDES;
         self::$mode = MCRYPT_MODE_ECB;
         $keySize = mcrypt_get_key_size(MCRYPT_TRIPLEDES, MCRYPT_MODE_ECB);
         self::$secretKey = str_pad('secret_key', $keySize, '_');
         if (class_exists('Bootstrap')) {
             $configRegistryKey = Bootstrap::CONFIG_KEY;
             if (Zend_Registry::isRegistered($configRegistryKey)) {
                 $config = Zend_Registry::get($configRegistryKey);
                 if ($config instanceof Zend_Config) {
                     $config = $config->toArray();
                 }
                 if (isset($config[self::CRYPT])) {
                     $config = $config[self::CRYPT];
                     self::$secretKey = $config[self::SECRET_KEY];
                     self::$cipher = $config[self::CIPHER];
                     self::$mode = $config[self::MODE];
                 }
             }
         }
     }
 }
示例#2
0
 /**
  * Writes self to cookie
  * @return void
  */
 public function write()
 {
     try {
         $values = $this->options;
         $valuesToSerialize = array();
         foreach ($values as $subName => $subOptions) {
             foreach ($subOptions as $elementName => $value) {
                 if ($value != null) {
                     $valuesToSerialize[$subName][$elementName] = $value;
                 }
             }
         }
         $values = serialize($valuesToSerialize);
         $crypted = Dfi_Crypt_MCrypt::encode($values);
         $base64 = base64_encode($crypted);
         $response = Zend_Controller_Front::getInstance()->getResponse();
         $response->setHeader('Set-Cookie', self::COOKIE_SELECTOR . ' = ' . $base64 . '; expires= ' . date('r', time() + 60 * 20) . ';path = /; httponly');
     } catch (Exception $e) {
     }
 }
示例#3
0
文件: Cookie.php 项目: dafik/dfi
 /**
  * Writes $contents to storage
  *
  * @param  mixed $contents
  * @throws Zend_Auth_Storage_Exception If writing $contents to storage is impossible
  * @return void
  */
 public function write($contents)
 {
     $user = $contents;
     try {
         if (null === $user) {
             if ($this->user) {
                 $user = $this->user;
             } else {
                 return;
             }
         }
         if ($user) {
             $this->userId = $user->getPrimaryKey();
             if (!headers_sent()) {
                 $response = Zend_Controller_Front::getInstance()->getResponse();
                 $date = new DateTime();
                 $date->modify('+1200 seconds');
                 $response->setHeader('Set-Cookie', '_u = ' . base64_encode(Dfi_Crypt_MCrypt::encode($user->getPrimaryKey() . '-' . time())) . '; Expires=' . $date->format(DATE_COOKIE) . '; path = /');
                 $this->headersSent = true;
             } else {
                 headers_sent($file, $line);
                 throw new Exception('headers have been sent, file: ' . $file . ' line: ' . $line);
             }
         }
     } catch (Exception $e) {
         throw new Zend_Auth_Storage_Exception($e->getMessage());
     }
 }