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


PHP Rand::getBytes方法代码示例

本文整理汇总了PHP中Zend\Math\Rand::getBytes方法的典型用法代码示例。如果您正苦于以下问题:PHP Rand::getBytes方法的具体用法?PHP Rand::getBytes怎么用?PHP Rand::getBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Math\Rand的用法示例。


在下文中一共展示了Rand::getBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testRandInteger

 /**
  * A Monte Carlo test that generates $cycles numbers from 0 to $tot
  * and test if the numbers are above or below the line y=x with a
  * frequency range of [$min, $max]
  *
  * Note: this code is inspired by the random number generator test
  * included in the PHP-CryptLib project of Anthony Ferrara
  * @see https://github.com/ircmaxell/PHP-CryptLib
  *
  * @dataProvider provideRandInt
  */
 public function testRandInteger($num, $valid, $cycles, $tot, $min, $max, $strong)
 {
     try {
         $test = Rand::getBytes(1, $strong);
     } catch (\Zend\Math\Exception\RuntimeException $e) {
         $this->markTestSkipped($e->getMessage());
     }
     $i = 0;
     $count = 0;
     do {
         $up = 0;
         $down = 0;
         for ($i = 0; $i < $cycles; $i++) {
             $x = Rand::getInteger(0, $tot, $strong);
             $y = Rand::getInteger(0, $tot, $strong);
             if ($x > $y) {
                 $up++;
             } elseif ($x < $y) {
                 $down++;
             }
         }
         $this->assertGreaterThan(0, $up);
         $this->assertGreaterThan(0, $down);
         $ratio = $up / $down;
         if ($ratio > $min && $ratio < $max) {
             $count++;
         }
         $i++;
     } while ($i < $num && $count < $valid);
     if ($count < $valid) {
         $this->fail('The random number generator failed the Monte Carlo test');
     }
 }
开发者ID:razvansividra,项目名称:pnlzf2-1,代码行数:44,代码来源:RandTest.php

示例2: export

 public function export()
 {
     $path = __DIR__ . '/../../../../../../public/xls/';
     if (!is_dir($path)) {
         throw new \Exception("Please make sure that 'public/xls' directory exists");
     }
     $fileName = str_replace("/", ".", base64_encode(Rand::getBytes(6, true)) . '_' . date("Y-m-d-H:i:s") . '.xls');
     $file = fopen($path . $fileName, "w");
     $count = 0;
     $html = null;
     $html .= "<table>";
     $html .= "<tr>";
     foreach ($this->headers as $headers) {
         $html .= "<th>{$headers}</th>";
     }
     $html .= "</tr>";
     foreach ($this->resultFormatedData as $data) {
         foreach ($data as $colunas) {
             $count++;
             if ($count == 0) {
                 $html .= "<tr>";
             }
             $html .= "<td>{$colunas}</td>";
             if ($count == count($this->headers)) {
                 $html .= "</tr>";
                 $count = 0;
             }
         }
     }
     fputs($file, utf8_decode($html));
     fclose($file);
     return '/xls/' . $fileName;
 }
开发者ID:vitorbarros,项目名称:vmb-zf2-data-export-module,代码行数:33,代码来源:XLSExport.php

示例3: create

 /**
  * Bcrypt
  *
  * @param  string $password
  * @throws Exception\RuntimeException
  * @return string
  */
 public function create($password)
 {
     if (empty($this->salt)) {
         $salt = Rand::getBytes(self::MIN_SALT_SIZE);
     } else {
         $salt = $this->salt;
     }
     $salt64 = substr(str_replace('+', '.', base64_encode($salt)), 0, 22);
     /**
      * Check for security flaw in the bcrypt implementation used by crypt()
      * @see http://php.net/security/crypt_blowfish.php
      */
     if (PHP_VERSION_ID >= 50307 && !$this->backwardCompatibility) {
         $prefix = '$2y$';
     } else {
         $prefix = '$2a$';
         // check if the password contains 8-bit character
         if (preg_match('/[\\x80-\\xFF]/', $password)) {
             throw new Exception\RuntimeException('The bcrypt implementation used by PHP can contain a security flaw ' . 'using password with 8-bit character. ' . 'We suggest to upgrade to PHP 5.3.7+ or use passwords with only 7-bit characters');
         }
     }
     $hash = crypt($password, $prefix . $this->cost . '$' . $salt64);
     if (strlen($hash) < 13) {
         throw new Exception\RuntimeException('Error during the bcrypt generation');
     }
     return $hash;
 }
开发者ID:ocpyosep78,项目名称:erp,代码行数:34,代码来源:Bcrypt.php

示例4: getStorageBaseName

 /**
  * Get the base name of the persistently stored file.
  *
  * @return string
  */
 public function getStorageBaseName()
 {
     if (isset($this->storageBaseName)) {
         return $this->storageBaseName;
     }
     $this->storageBaseName = bin2hex(Rand::getBytes(20));
     return $this->storageBaseName;
 }
开发者ID:patrova,项目名称:omeka-s,代码行数:13,代码来源:File.php

示例5: __construct

 public function __construct(array $options = array())
 {
     (new Hydrator\ClassMethods())->hydrate($options, $this);
     $this->created = new \DateTime("now");
     $this->modified = new \DateTime("now");
     $this->salt = base64_encode(Rand::getBytes(8, true));
     $this->activekey = md5($this->email . $this->salt);
 }
开发者ID:GSilva18,项目名称:SISEDS,代码行数:8,代码来源:User.php

示例6: __construct

 /**
  * @param array $options
  */
 public function __construct(array $options = [])
 {
     (new Hydrator\ClassMethods())->hydrate($options, $this);
     $this->updatedAt = new \DateTime('now');
     $this->createdAt = new \DateTime('now');
     $this->salt = base64_encode(Rand::getBytes(8, true));
     $this->activationKey = md5($this->email . $this->salt);
 }
开发者ID:argentinaluiz,项目名称:Learning-ZF2,代码行数:11,代码来源:User.php

示例7: create

 public function create($password)
 {
     if (empty($this->salt)) {
         $salt = $this->salt = Rand::getBytes(self::MIN_SALT_SIZE);
     } else {
         $salt = $this->salt;
     }
     return parent::create($password);
 }
开发者ID:fwk,项目名称:security,代码行数:9,代码来源:Bcrypt.php

示例8: create

 /**
  * Bcrypt
  *
  * @param  string $password
  * @throws Exception\RuntimeException
  * @return string
  */
 public function create($password)
 {
     $options = ['cost' => (int) $this->cost];
     if (PHP_VERSION_ID < 70000) {
         // salt is deprecated from PHP 7.0
         $salt = $this->salt ?: Rand::getBytes(self::MIN_SALT_SIZE);
         $options['salt'] = $salt;
     }
     return password_hash($password, PASSWORD_BCRYPT, $options);
 }
开发者ID:chrisbautista,项目名称:bcit-applied-development,代码行数:17,代码来源:Bcrypt.php

示例9: array

 function __construct(array $options = array())
 {
     // Preencher automático os valores no objeto
     //        $hydrator = new Hydrator\ClassMethods;
     //        $hydrator->hydrate($options, $this);
     (new Hydrator\ClassMethods())->hydrate($options, $this);
     $this->createdAt = new \DateTime('now', new \DateTimeZone('America/Sao_Paulo'));
     $this->updatedAt = new \DateTime('now', new \DateTimeZone('America/Sao_Paulo'));
     $this->salt = base64_encode(Rand::getBytes(8, true));
     $this->activationKey = md5($this->email . $this->salt);
 }
开发者ID:alexcomput,项目名称:ZF2Project,代码行数:11,代码来源:User.php

示例10: __construct

 public function __construct(array $options = array())
 {
     /*
     $hydrator = new Hydrator\ClassMethods();
     $hydrator->hydrate($options, $this);
     */
     (new Hydrator\ClassMethods())->hydrate($options, $this);
     $this->createdAt = new \DateTime("now");
     $this->updateAt = new \DateTime("now");
     $this->salt = base64_encode(Rand::getBytes(8, TRUE));
     $this->activationKey = md5($this->email . $this->salt);
 }
开发者ID:EnnioSimoes,项目名称:Base-ZF2-Doctrine,代码行数:12,代码来源:User.php

示例11: __construct

 public function __construct(array $options = array())
 {
     (new Hydrator\ClassMethods())->hydrate($options, $this);
     // recebe o array $options que é passado no construtor
     /*
     $hydrator = new Hydrator\ClassMethods;
     $hydrator->hydrate($options, $this);
     */
     $this->createdAt = new \DateTime("now");
     $this->updatedAt = new \DateTime("now");
     $this->salt = base64_encode(Rand::getBytes(8, true));
     $this->activationKey = md5($this->email . $this->salt);
 }
开发者ID:souzagabi,项目名称:Agenda,代码行数:13,代码来源:User.php

示例12: __construct

 public function __construct(array $options = array())
 {
     /*
      $hydrator = new Hydrator\ClassMethods;
      $hydrator->hydrate($options, $this);
     */
     $this->createdAt = new \DateTime("now");
     $this->updatedAt = new \DateTime("now");
     $this->salt = base64_encode(Rand::getBytes(8, true));
     $this->activationKey = md5($this->email . $this->salt);
     (new Hydrator\ClassMethods())->hydrate($options, $this);
     // recebe o array $options que é passado no construtoressa linha tem que ser por ultimo para gravar a senha corretamente
 }
开发者ID:souzagabi,项目名称:Agenda,代码行数:13,代码来源:User.php

示例13: keygen

 public function keygen($pass = null)
 {
     $uniqueRandonStr = function ($lenght) {
         $bytes = openssl_random_pseudo_bytes($lenght);
         return bin2hex($bytes);
     };
     if ($pass == null) {
         $pass = $uniqueRandonStr(32);
     }
     $salt = Rand::getBytes(strlen($pass), true);
     $key = Pbkdf2::calc('sha256', $pass, $salt, 10000, strlen($pass) * 2);
     return $key;
 }
开发者ID:thiagormoreira,项目名称:ClickMark-Api,代码行数:13,代码来源:Crypt.php

示例14: formRand

 public function formRand()
 {
     $bytes = Rand::getBytes(32, true);
     $this->data->bytes = "Random bytes (in Base64): " . base64_encode($bytes);
     $boolean = Rand::getBoolean();
     $this->data->boolean = "Random boolean: " . ($boolean ? 'true' : 'false');
     $integer = Rand::getInteger(0, 1000);
     $this->data->integer = "Random integer in [0-1000]: " . $integer;
     $float = Rand::getFloat();
     $this->data->float = "Random float in [0-1): " . $float;
     $string = Rand::getString(32, 'abcdefghijklmnopqrstuvwxyz', true);
     $this->data->string = "Random string in latin alphabet:" . $string;
     $this->render();
 }
开发者ID:joshuacoddingyou,项目名称:php,代码行数:14,代码来源:zendController.php

示例15: __construct

 public function __construct(array $options = array())
 {
     //Implementa o Hydrator nesta entidade
     /* As 2 linhas abaixo é igual a proxima linha descomentada
        $hydrator = new Hydrator\ClassMethods;
        $hydrator->hydrate($options, $this);
        */
     (new Hydrator\ClassMethods())->hydrate($options, $this);
     $this->createdAt = new \DateTime("now");
     $this->updatedAt = new \DateTime("now");
     //Gera caracteres 'bizarros' para criptografar a senha de ativacao
     $this->salt = base64_encode(Rand::getBytes(8, true));
     $this->activationKey = md5($this->email . $this->salt);
 }
开发者ID:Tortinhex,项目名称:Zend2Skeleton,代码行数:14,代码来源:User.php


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