/** * testMultipleUuidGeneration method * * @return void */ public function testMultipleUuidGeneration() { $check = array(); $count = mt_rand(10, 1000); $pattern = "/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\$/"; for ($i = 0; $i < $count; $i++) { $result = String::uuid(); $match = (bool) preg_match($pattern, $result); $this->assertTrue($match); $this->assertFalse(in_array($result, $check)); $check[] = $result; } }
public function startup(Event $event) { if ($this->config('use_session_salt')) { if (!$this->controller->request->session()->check('Alaxos.SpamFilterComponent.salt')) { $this->controller->request->session()->write('Alaxos.SpamFilterComponent.salt', String::uuid()); } } elseif ($this->controller->request->session()->check('Alaxos.SpamFilterComponent.salt')) { $this->controller->request->session()->delete('Alaxos.SpamFilterComponent.salt'); } $salt = $this->get_session_salt(); $this->controller->components()->load('Security')->config('unlockedFields', [SecurityTool::get_today_fieldname($salt)]); $this->controller->components()->load('Security')->config('unlockedFields', [SecurityTool::get_yesterday_fieldname($salt)]); /* * Pass Session salt to view in order to be available in AlaxosFormHelper */ $this->controller->set('_alaxos_spam_filter_salt', $salt); }
/** * Generate authorization hash. * * @return string Hash */ public static function generateAuthKey() { return Security::hash(String::uuid()); }
/** * Generate a new UUID * * @return string A new primary key value. */ public function newId() { return String::uuid(); }
public function getUploadPath(Entity $entity, $path, $extension) { $replace = array('%uuid' => String::uuid(), '%id' => $entity->id, '%y' => date('Y'), '%m' => date('m'), '/' => DS); $path = $this->_config['assets_dir'] . DS . Inflector::tableize($entity->source()) . DS . strtr($path, $replace) . '.' . $extension; return $path; }
/** * Generate String representation of Records * * @param \Cake\Database\Schema\Table $table Table schema array * @param int $recordCount The number of records to generate. * @return array Array of records to use in the fixture. */ protected function _generateRecords(Table $table, $recordCount = 1) { $records = []; for ($i = 0; $i < $recordCount; $i++) { $record = []; foreach ($table->columns() as $field) { $fieldInfo = $table->column($field); $insert = ''; switch ($fieldInfo['type']) { case 'integer': case 'float': $insert = $i + 1; break; case 'string': case 'binary': $isPrimary = in_array($field, $table->primaryKey()); if ($isPrimary) { $insert = String::uuid(); } else { $insert = "Lorem ipsum dolor sit amet"; if (!empty($fieldInfo['length'])) { $insert = substr($insert, 0, (int) $fieldInfo['length'] - 2); } } break; case 'timestamp': $insert = time(); break; case 'datetime': $insert = date('Y-m-d H:i:s'); break; case 'date': $insert = date('Y-m-d'); break; case 'time': $insert = date('H:i:s'); break; case 'boolean': $insert = 1; break; case 'text': $insert = "Lorem ipsum dolor sit amet, aliquet feugiat."; $insert .= " Convallis morbi fringilla gravida,"; $insert .= " phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin"; $insert .= " venenatis cum nullam, vivamus ut a sed, mollitia lectus. Nulla"; $insert .= " vestibulum massa neque ut et, id hendrerit sit,"; $insert .= " feugiat in taciti enim proin nibh, tempor dignissim, rhoncus"; $insert .= " duis vestibulum nunc mattis convallis."; break; } $record[$field] = $insert; } $records[] = $record; } return $records; }
/** * Simulates direct writing to a system file by creating the file in /tmp * using default credentials, then shelling a `mv` to the desired location * as root. * * @param string $file Full path to the file to write. * @param string $content Containing file body. * @return boolean True if the write is successful */ protected function _writeSystemFile($file, $content) { $this->_log("Writing system file"); $tempFile = '/tmp/' . String::uuid(); $fh = new File($tempFile, true); $fh->write($content); // Move the tempfile if (!$this->shell("mv {$tempFile} {$file}", 'root')) { $this->_error("* Error moving {$tempFile} to {$file}"); return false; } $this->_log("* Successfully wrote {$file}"); return true; }
/** * Just a testing method * * @return void */ public function testing() { Hash::extract(); $alias = String::uuid(); $full = \Cake\Utility\String::truncate($param1, $param2); }
/** * Set the cookie in the response. * * Also sets the request->params['_csrfToken'] so the newly minted * token is available in the request data. * * @param \Cake\Network\Request $request The request object. * @param \Cake\Network\Response $response The response object. */ protected function _setCookie(Request $request, Response $response) { $value = Security::hash(String::uuid(), 'sha1', true); $request->params['_csrfToken'] = $value; $response->cookie(['name' => $this->_config['cookieName'], 'value' => $value, 'expiry' => $this->_config['expiry'], 'path' => $request->base, 'secure' => $this->_config['secure']]); }