本文整理汇总了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');
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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
}
示例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;
}
示例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();
}
示例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);
}