本文整理汇总了PHP中str::random方法的典型用法代码示例。如果您正苦于以下问题:PHP str::random方法的具体用法?PHP str::random怎么用?PHP str::random使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类str
的用法示例。
在下文中一共展示了str::random方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add
public function add($data)
{
$data['id'] = str::random(32);
$this->data[$data['id']] = $data;
$this->save();
return $data['id'];
}
示例2: create
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;
}
示例3: id
public function id()
{
$id = str::random(32);
while ($this->index()->where('id', '=', $id)->one()) {
$id = str::random(32);
}
return $id;
}
示例4: __construct
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();
}
示例5: kill
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();
}
示例6: testSize
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);
}
示例7: csrf
/**
* 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;
}
示例8: create_token
/**
* 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;
}
}
}
示例9: testRandom
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'));
}
示例10: csrf
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;
}
示例11: generateToken
public function generateToken()
{
return sha1($this->username() . str::random(32) . time());
}
示例12: logout
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());
}
示例13: hash
/**
* 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);
}
示例14: generateKey
public function generateKey()
{
return str::random(64);
}
示例15: generate_challenge
/**
* 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)));
}