当前位置: 首页>>代码示例>>PHP>>正文


PHP str::random方法代码示例

本文整理汇总了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'];
 }
开发者ID:nsteiner,项目名称:kdoc,代码行数:7,代码来源:store.php

示例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;
 }
开发者ID:nsteiner,项目名称:kdoc,代码行数:31,代码来源:children.php

示例3: id

 public function id()
 {
     $id = str::random(32);
     while ($this->index()->where('id', '=', $id)->one()) {
         $id = str::random(32);
     }
     return $id;
 }
开发者ID:Zegnat,项目名称:library,代码行数:8,代码来源:library.php

示例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();
 }
开发者ID:LucasFyl,项目名称:korakia,代码行数:10,代码来源:PaginationTest.php

示例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();
 }
开发者ID:scheibome,项目名称:kirbycms-extensions,代码行数:10,代码来源:auth.php

示例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);
 }
开发者ID:LucasFyl,项目名称:korakia,代码行数:10,代码来源:DirTest.php

示例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;
}
开发者ID:muten84,项目名称:luigibifulco.it,代码行数:17,代码来源:helpers.php

示例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;
         }
     }
 }
开发者ID:shnhrrsn-abandoned,项目名称:EightPHP,代码行数:20,代码来源:authusertoken.php

示例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'));
 }
开发者ID:getkirby,项目名称:toolkit,代码行数:13,代码来源:StrTest.php

示例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;
 }
开发者ID:biggtfish,项目名称:Clean-Blog-Kirby-Theme,代码行数:16,代码来源:panel.php

示例11: generateToken

 public function generateToken()
 {
     return sha1($this->username() . str::random(32) . time());
 }
开发者ID:muten84,项目名称:luigibifulco.it,代码行数:4,代码来源:user.php

示例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());
 }
开发者ID:codecuts,项目名称:lanningsmith-website,代码行数:11,代码来源:user.php

示例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);
 }
开发者ID:aoimedia,项目名称:kosmonautensofa,代码行数:11,代码来源:password.php

示例14: generateKey

 public function generateKey()
 {
     return str::random(64);
 }
开发者ID:robinandersen,项目名称:robin,代码行数:4,代码来源:user.php

示例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)));
 }
开发者ID:enormego,项目名称:EightPHP,代码行数:10,代码来源:black.php


注:本文中的str::random方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。