random() 정적인 공개 메소드

Generates a random string
static public random ( integer $length = false ) : string
$length integer The length of the random string
리턴 string
예제 #1
0
파일: store.php 프로젝트: nsteiner/kdoc
 public function add($data)
 {
     $data['id'] = str::random(32);
     $this->data[$data['id']] = $data;
     $this->save();
     return $data['id'];
 }
예제 #2
0
파일: children.php 프로젝트: nsteiner/kdoc
 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
0
파일: library.php 프로젝트: Zegnat/library
 public function id()
 {
     $id = str::random(32);
     while ($this->index()->where('id', '=', $id)->one()) {
         $id = str::random(32);
     }
     return $id;
 }
예제 #4
0
 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
0
 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
0
 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
0
/**
 * 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
0
 /**
  * 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
0
 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
0
 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
0
 public function generateToken()
 {
     return sha1($this->username() . str::random(32) . time());
 }
예제 #12
0
 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
0
 /**
  * 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
0
 public function generateKey()
 {
     return str::random(64);
 }
예제 #15
0
파일: black.php 프로젝트: enormego/EightPHP
 /**
  * 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)));
 }
예제 #16
0
 /**
  * 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);
 }
예제 #17
0
파일: auth.php 프로젝트: alkaest2002/risky2
 public static function generateSha1Hash($value)
 {
     return sha1($value . str::random(32) . time());
 }