public function add($data) { $data['id'] = str::random(32); $this->data[$data['id']] = $data; $this->save(); return $data['id']; }
public function create($uid, $template, $content = array()) { if (empty($template)) { throw new Exception(l('pages.add.error.template')); } $uid = empty($uid) ? str::random(32) : $uid; $blueprint = new Blueprint($template); $data = array(); foreach ($blueprint->fields(null) as $key => $field) { $data[$key] = $field->default(); } $data = array_merge($data, $content); // create the new page and convert it to a page model $page = new Page($this->page, parent::create($uid, $template, $data)->dirname()); if (!$page) { throw new Exception(l('pages.add.error.create')); } kirby()->trigger('panel.page.create', $page); // subpage builder foreach ((array) $page->blueprint()->pages()->build() as $build) { $missing = a::missing($build, array('title', 'template', 'uid')); if (!empty($missing)) { continue; } $subpage = $page->children()->create($build['uid'], $build['template'], array('title' => $build['title'])); if (isset($build['num'])) { $subpage->sort($build['num']); } } return $page; }
public function id() { $id = str::random(32); while ($this->index()->where('id', '=', $id)->one()) { $id = str::random(32); } return $id; }
public function __construct() { $this->data = new Collection(); foreach (range(0, 99) as $key => $item) { $this->data->set($key, str::random()); } $this->url = 'http://getkirby.com'; $this->pages = $this->data->paginate(10, array('url' => $this->url)); $this->pagination = $this->pages->pagination(); }
protected static function kill() { self::$user = null; // overwrite the token $token = str::random(); // the cookie is valid for 24 hours cookie::set('authFrontend', $token, 60 * 60 * 24); // restart the session s::restart(); }
public function testSize() { dir::make($this->tmpDir); f::write($this->tmpDir . DS . 'testfile-1.txt', str::random(5)); f::write($this->tmpDir . DS . 'testfile-2.txt', str::random(5)); f::write($this->tmpDir . DS . 'testfile-3.txt', str::random(5)); $this->assertEquals(15, dir::size($this->tmpDir)); $this->assertEquals('15 b', dir::niceSize($this->tmpDir)); dir::remove($this->tmpDir); }
/** * Checks / returns a csrf token * * @param string $check Pass a token here to compare it to the one in the session * @return mixed Either the token or a boolean check result */ function csrf($check = null) { // make sure a session is started s::start(); if (is_null($check)) { $token = str::random(64); s::set('csrf', $token); return $token; } return $check === s::get('csrf') ? true : false; }
/** * Finds a new unique token, using a loop to make sure that the token does * not already exist in the database. This could potentially become an * infinite loop, but the chances of that happening are very unlikely. * * @return string */ protected function create_token() { while (true) { // Create a random token $token = str::random('alnum', 32); // Make sure the token does not already exist self::db()->use_master(YES); if (self::db()->select('user_token_id')->where('user_token_token', $token)->get($this->table_name)->count() === 0) { // A unique token has been found return $token; } } }
public function testRandom() { // choose a high length for a high probability of occurrence of a character of any type $length = 200; $this->assertRegexp("/^[[:alnum:]]+\$/", str::random()); $this->assertInternalType('string', str::random()); $this->assertEquals($length, strlen(str::random($length))); $this->assertRegexp("/^[[:alpha:]]+\$/", str::random($length, 'alpha')); $this->assertRegexp("/^[[:upper:]]+\$/", str::random($length, 'alphaUpper')); $this->assertRegexp("/^[[:lower:]]+\$/", str::random($length, 'alphaLower')); $this->assertRegexp("/^[[:digit:]]+\$/", str::random($length, 'num')); $this->assertFalse(str::random($length, 'something invalid')); }
public function csrf() { if (!is_null($this->csrf)) { return $this->csrf; } // see if there's a token in the session $token = s::get('csrf'); // create a new csrf token if not available yet if (str::length($token) !== 32) { $token = str::random(32); } // store the new token in the session s::set('csrf', $token); // create a new csrf token return $this->csrf = $token; }
public function generateToken() { return sha1($this->username() . str::random(32) . time()); }
function logout() { // overwrite the token $token = str::random(); // the cookie is valid for 24 hours cookie::set('auth', $token, 60 * 60 * 24); // restart the session s::restart(); // go to the homepage go(url()); }
/** * Generates a salted hash for a plaintext password * * @param string $plaintext * @return string */ public static function hash($plaintext) { $salt = substr(str_replace('+', '.', base64_encode(sha1(str::random(), true))), 0, 22); return crypt($plaintext, '$2a$10$' . $salt); }
public function generateKey() { return str::random(64); }
/** * Generates a new Captcha challenge. * * @return string the challenge answer */ public function generate_challenge() { // Complexity setting is used as character count return str::random('distinct', max(1, ceil(Captcha::$config['complexity'] / 1.5))); }
/** * Generates a new token for this form and session. */ private function generateToken() { $this->token = str::random(SendForm::TOKEN_LENGTH); s::set($this->id, $this->token); }
public static function generateSha1Hash($value) { return sha1($value . str::random(32) . time()); }