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'); } }
/** * 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; }
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..."); } }
/** * @return string */ public function createCode() { $factory = new RandomLibFactory(); $generator = $factory->getLowStrengthGenerator(); $randomString = $generator->generateString($this->confirmationCodeLength, $this->confirmationCodeCharacters); return $randomString; }
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); }
/** * @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; }
/** * 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; }
public function provideValidationData() { $factory = new Factory(); $generator = $factory->getLowStrengthGenerator(); return [[$generator->generateString(8), true], [$generator->generateString(8), false]]; }
public function passwordProvider() { $factory = new Factory(); $generator = $factory->getLowStrengthGenerator(); return [[$generator->generateString(8), 'password', 'not_identical_password']]; }
/** * 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) . '*****@*****.**'; }
public function uniqid($prefix) { $random = $this->randomLib->getLowStrengthGenerator(); $characters = '0123456789abcdefghijklmnopqrstuvwxyz'; return $prefix . $random->generateString(12, $characters); }
/** * @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; }
public function uniqid() { $random = $this->randomLib->getLowStrengthGenerator(); $characters = '0123456789abcdefghijklmnopqrstuvwxyz' . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; return $random->generateString(12, $characters); }
public static function create() { $factory = new Factory(); return new NonceProvider($factory->getLowStrengthGenerator()); }
/** * 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(); } }