本文整理汇总了PHP中RandomLib\Factory::getLowStrengthGenerator方法的典型用法代码示例。如果您正苦于以下问题:PHP Factory::getLowStrengthGenerator方法的具体用法?PHP Factory::getLowStrengthGenerator怎么用?PHP Factory::getLowStrengthGenerator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RandomLib\Factory
的用法示例。
在下文中一共展示了Factory::getLowStrengthGenerator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getGenerator
public function getGenerator($strength)
{
switch ($strength) {
case 'low':
return $this->factory->getLowStrengthGenerator();
case 'medium':
return $this->factory->getMediumStrengthGenerator();
case 'high':
throw new \InvalidArgumentException('"high" strength is currently unavailable');
default:
throw new \InvalidArgumentException('Could not find a generator for the specified strength');
}
}
示例2: generateOneTimeToken
/**
* Create a one time token
*
* Generates a low strength random number of size $bytes and hash with the
* algorithm specified in $hash.
*
* @param string $hash hash function to use
* @param integer $bytes the number of random bit to generate
*
* @return string hashed token
*/
public static function generateOneTimeToken($hash = 'sha512', $bytes = 64)
{
$factory = new Factory();
$generator = $factory->getLowStrengthGenerator();
$token = hash($hash, $generator->generate($bytes));
return $token;
}
示例3: migrateSettingsFile
public static function migrateSettingsFile(Event $event = null)
{
if ($event !== null) {
$event->getIO()->write("Migrating old setting file...");
}
if ($event) {
$root_dir = realpath('');
} else {
$root_dir = realpath('../../');
}
if (file_exists($root_dir . '/app/config/parameters.yml')) {
return false;
}
if (file_exists($root_dir . '/' . self::SETTINGS_FILE)) {
$tmp_settings = file_get_contents($root_dir . '/' . self::SETTINGS_FILE);
if (strpos($tmp_settings, '_DB_SERVER_') !== false) {
$tmp_settings = preg_replace('/(\'|")\\_/', '$1_LEGACY_', $tmp_settings);
file_put_contents($root_dir . '/' . self::SETTINGS_FILE, $tmp_settings);
include $root_dir . '/' . self::SETTINGS_FILE;
$factory = new RandomLib\Factory();
$generator = $factory->getLowStrengthGenerator();
$secret = $generator->generateString(56);
$default_parameters = Yaml::parse($root_dir . '/app/config/parameters.yml.dist');
$parameters = array('parameters' => array('database_host' => _LEGACY_DB_SERVER_, 'database_port' => '~', 'database_user' => _LEGACY_DB_USER_, 'database_password' => _LEGACY_DB_PASSWD_, 'database_name' => _LEGACY_DB_NAME_, 'database_prefix' => _LEGACY_DB_PREFIX_, 'database_engine' => _LEGACY_MYSQL_ENGINE_, 'cookie_key' => _LEGACY_COOKIE_KEY_, 'cookie_iv' => _LEGACY_COOKIE_IV_, 'ps_caching' => _LEGACY_PS_CACHING_SYSTEM_, 'ps_cache_enable' => _LEGACY_PS_CACHE_ENABLED_, 'ps_creation_date' => _LEGACY_PS_CREATION_DATE_, 'secret' => $secret, 'mailer_transport' => 'smtp', 'mailer_host' => '127.0.0.1', 'mailer_user' => '~', 'mailer_password' => '~') + $default_parameters['parameters']);
if (file_put_contents($root_dir . '/app/config/parameters.yml', Yaml::dump($parameters))) {
$settings_content = "<?php\n";
$settings_content .= "//@deprecated 1.7";
file_put_contents($root_dir . '/' . self::SETTINGS_FILE, $settings_content);
}
}
}
if ($event !== null) {
$event->getIO()->write("Finished...");
}
}
示例4: createCode
/**
* @return string
*/
public function createCode()
{
$factory = new RandomLibFactory();
$generator = $factory->getLowStrengthGenerator();
$randomString = $generator->generateString($this->confirmationCodeLength, $this->confirmationCodeCharacters);
return $randomString;
}
示例5: let
function let(Factory $factory, Generator $low, Generator $medium)
{
$factory->getMediumStrengthGenerator()->willReturn($medium);
$factory->getLowStrengthGenerator()->willReturn($low);
$this->beConstructedWith($factory);
$defaults = ['length' => 32, 'chars' => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'strength' => 'medium'];
$this->setOptions($defaults);
}
示例6: getLargeMessage
/**
* @return string
*/
public function getLargeMessage()
{
if (!$this->largeMessage) {
$filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5(__METHOD__);
if (file_exists($filename)) {
// TODO Check file content length.
return file_get_contents($filename);
}
$factory = new Factory();
$generator = $factory->getLowStrengthGenerator();
$this->largeMessage = $generator->generateString($this->largeMessageLength);
file_put_contents($filename, $this->largeMessage);
}
return $this->largeMessage;
}
示例7: getLowStrengthGenerator
/**
* Convenience method to get a low strength random number generator.
*
* Low Strength should be used anywhere that random strings are needed
* in a non-cryptographical setting. They are not strong enough to be
* used as keys or salts. They are however useful for one-time use tokens.
*
* @return $this
*/
public function getLowStrengthGenerator()
{
$this->generator = $this->factory->getLowStrengthGenerator();
return $this;
}
示例8: provideValidationData
public function provideValidationData()
{
$factory = new Factory();
$generator = $factory->getLowStrengthGenerator();
return [[$generator->generateString(8), true], [$generator->generateString(8), false]];
}
示例9: passwordProvider
public function passwordProvider()
{
$factory = new Factory();
$generator = $factory->getLowStrengthGenerator();
return [[$generator->generateString(8), 'password', 'not_identical_password']];
}
示例10: generateEmail
/**
* Generate a new valid email adress
* @return string
*/
private function generateEmail()
{
$factory = new Factory();
$generator = $factory->getLowStrengthGenerator();
return $generator->generateString(8, TokenManipulator::LETTERS_AND_NUMBERS) . '_email@email.com';
}
示例11: uniqid
public function uniqid($prefix)
{
$random = $this->randomLib->getLowStrengthGenerator();
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
return $prefix . $random->generateString(12, $characters);
}
示例12: randomInt
/**
* @param int $min
* @param int $max
*
* @return int
*
* @codeCoverageIgnore
*/
public static function randomInt($min = 0, $max = PHP_INT_MAX)
{
$factory = new Factory();
$generator = $factory->getLowStrengthGenerator();
$num = $generator->generateInt($min, $max);
unset($factory);
unset($generator);
return $num;
}
示例13: uniqid
public function uniqid()
{
$random = $this->randomLib->getLowStrengthGenerator();
$characters = '0123456789abcdefghijklmnopqrstuvwxyz' . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
return $random->generateString(12, $characters);
}
示例14: create
public static function create()
{
$factory = new Factory();
return new NonceProvider($factory->getLowStrengthGenerator());
}
示例15: __construct
/**
* Constructor.
*
* @param ConnectionOptions $options Connection options object.
*/
public function __construct(ConnectionOptions $options = null)
{
$this->pings = 0;
$this->pubs = 0;
$this->subscriptions = [];
$this->options = $options;
$randomFactory = new Factory();
$this->randomGenerator = $randomFactory->getLowStrengthGenerator();
if (is_null($options)) {
$this->options = new ConnectionOptions();
}
}