コード例 #1
0
ファイル: CCStr.php プロジェクト: clancats/core
 /**
  * test random string
  */
 public function testRandom()
 {
     $this->assertEquals(strlen(CCStr::random(5)), 5);
     $this->assertEquals(strlen(CCStr::random()), 25);
     // test random charset
     $random_str = CCStr::random(10, 'lowercase');
     for ($i = 0; $i < strlen($random_str); $i++) {
         $this->assertTrue(strpos(CCStr::ALPHA_LOW, $random_str[$i]) !== false);
     }
 }
コード例 #2
0
ファイル: doctor.php プロジェクト: clancats/core
 /**
  * Try to generate a security key in the main config file
  *
  * @param array 		$params 
  */
 public function action_security_key($params)
 {
     $path = \CCPath::config('main.config' . EXT);
     // Check if the file exists
     if (!file_exists($path)) {
         $this->error('Could not find main configuration file.');
         return;
     }
     // Now try to replace the placeholder with
     // an new generated key
     $data = \CCFile::read($path);
     if (strpos($data, '{{security salt here}}') === false) {
         $this->error('The key has already been generated or set.');
         return;
     }
     $data = str_replace('{{security salt here}}', \CCStr::random(32, 'password'), $data);
     // write the data back down
     \CCFile::write($path, $data);
     $this->success('The key has been generated.');
 }
コード例 #3
0
ファイル: CCStorage.php プロジェクト: clancats/core
 /**
  * Prepares a file with the parameters
  *
  * @param string 		$file
  * @return $file
  */
 public static function file($file)
 {
     $params = array_merge(static::$params, array('time' => time(), 'fingerprint' => \CCSession::fingerprint(), 'random' => CCStr::random()));
     foreach ($params as $param => $value) {
         $file = str_replace(':' . $param, $value, $file);
     }
     return $file;
 }
コード例 #4
0
ファイル: Manager.php プロジェクト: clancats/core
 /**
  * Generate a new session id and checks the dirver for dublicates.
  *
  * @return string	The new generated session id.
  */
 public function regenerate()
 {
     do {
         $id = \CCStr::random(32);
     } while ($this->_driver->has($id));
     $this->fingerprint = sha1($id);
     return $this->id = $id;
 }