/** * Generates a random string * * @param int Size * @return string */ function noise($size = 32) { $factory = new RandomLib\Factory(); $generator = $factory->getLowStrengthGenerator(); $pool = 'abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; return $generator->generateString($size, $pool); }
public static function provideGenerators() { $factory = new \RandomLib\Factory(); $generator = $factory->getLowStrengthGenerator(); $sources = $generator->getSources(); $ret = array(); $ret[] = array(new Generator($sources, new \RandomLib\Mixer\Hash()), 10000, 'hash'); return $ret; }
/** * Register the application services. * * @return void */ public function register() { $this->mergeConfigFrom(__DIR__ . '/config/laravel-random.php', 'laravel-random'); $this->app->singleton('random', function ($app) { $factory = new \RandomLib\Factory(); $strength = $app['config']->get('laravel-random.strength'); if ($strength === 'high') { return $factory->getHighStrengthGenerator(); } if ($strength === 'medium') { return $factory->getMediumStrengthGenerator(); } return $factory->getLowStrengthGenerator(); }); }
/** * Get a random string * * @param integer $length of the random string * @param boolean $high strength of the random source (since 9.2) * * @return random string **/ static function getRandomString($length, $high = false) { $factory = new RandomLib\Factory(); if ($high) { /* Notice "High" imply mcrypt extension, unwanted for now See https://github.com/ircmaxell/RandomLib/issues/57 */ $generator = $factory->getMediumStrengthGenerator(); } else { $generator = $factory->getLowStrengthGenerator(); } return $generator->generateString($length, RandomLib\Generator::CHAR_LOWER + RandomLib\Generator::CHAR_DIGITS); }