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


PHP Factory::getMediumStrengthGenerator方法代码示例

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


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

示例1: generateString

 /**
  * Generate a medium-strength random string of the given length.
  *
  * @param int $length length of the generated string
  * @param string $characters characters to use to generate the string
  * @return string
  */
 public function generateString($length, $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
 {
     if (is_null($this->_factory)) {
         $this->_factory = new \RandomLib\Factory();
         $this->_generator = $this->_factory->getMediumStrengthGenerator();
     }
     return $this->_generator->generateString($length, $characters);
 }
开发者ID:josephsnyder,项目名称:Midas,代码行数:15,代码来源:RandomComponent.php

示例2: 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');
     }
 }
开发者ID:zittix,项目名称:StringGeneratorBundle,代码行数:13,代码来源:SecureStringGenerator.php

示例3: generateKey

 /**
  * Create a medium strength key
  *
  * Generates a medium 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 bytes to generate
  *
  * @return string hashed token
  */
 public static function generateKey($hash = 'sha512', $bytes = 128)
 {
     $factory = new Factory();
     $generator = $factory->getMediumStrengthGenerator();
     $token = hash($hash, $generator->generate($bytes));
     return $token;
 }
开发者ID:ming-hai,项目名称:XoopsCore,代码行数:18,代码来源:Random.php

示例4: saveTokenAction

 /**
  * @param Request $request
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function saveTokenAction(Request $request)
 {
     $apiToken = new ApiToken();
     $apiToken->setUser($this->getUser());
     $formBuilder = $this->createFormBuilder($apiToken, array('action' => $this->generateUrl('api_key_create'), 'data_class' => 'CSBill\\UserBundle\\Entity\\ApiToken'));
     $formBuilder->add('name');
     $form = $formBuilder->getForm();
     $form->handleRequest($request);
     $response = array();
     if ($form->isValid()) {
         $factory = new Factory();
         $generator = $factory->getMediumStrengthGenerator();
         $token = $generator->generateString(64, Generator::CHAR_ALNUM);
         $apiToken->setToken($token);
         $this->save($apiToken);
         $response['status'] = 0;
         $response['token'] = array('token' => $apiToken->getToken(), 'name' => $apiToken->getName(), 'id' => $apiToken->getId());
         return $this->json($response);
     } else {
         $response['status'] = 1;
     }
     $content = $this->renderView('CSBillUserBundle:Api:create.html.twig', array('form' => $form->createView()));
     $response['content'] = $content;
     return $this->json($response);
 }
开发者ID:Codixis,项目名称:CSBill,代码行数:30,代码来源:ApiController.php

示例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);
 }
开发者ID:zittix,项目名称:StringGeneratorBundle,代码行数:8,代码来源:SecureStringGeneratorSpec.php

示例6: testGetSetKeyGenerator

 public function testGetSetKeyGenerator()
 {
     $this->assertInstanceOf('QueryAuth\\KeyGenerator', $this->requestSigner->getKeyGenerator());
     $randomFactory = new RandomFactory();
     $keyGenerator = new KeyGenerator($randomFactory->getMediumStrengthGenerator());
     $this->requestSigner->setKeyGenerator($keyGenerator);
     $this->assertSame($keyGenerator, $this->requestSigner->getKeyGenerator());
 }
开发者ID:jeremykendall,项目名称:query-auth,代码行数:8,代码来源:RequestSignerTest.php

示例7: __construct

 public function __construct(Generator $generator = null)
 {
     $this->generator = $generator;
     if ($this->generator == null) {
         $factory = new Factory();
         $this->generator = $factory->getMediumStrengthGenerator();
     }
 }
开发者ID:00f100,项目名称:uuid,代码行数:8,代码来源:RandomLibAdapter.php

示例8: random

 /**
  * Generates a random number in the provided range, where all possible values are equally likely. (Even distribution.)
  *
  * NOTE: If $max is more than PHP_INT_MAX or $min is less than PHP_INT_MIN, no additional entropy will be gained for
  * the random number, and the distribution will become less evenly distributed across all possible values due to
  * rounding.
  *
  * @param $min
  * @param $max
  * @return NumberInterface
  */
 public function random($min = 0, $max = PHP_INT_MAX)
 {
     $min = Numbers::makeOrDont(Numbers::IMMUTABLE, $min);
     $max = Numbers::makeOrDont(Numbers::IMMUTABLE, $max);
     $difference = new ImmutableNumber(BCProvider::add($max->absValue(), $min->absValue()));
     $randFactory = new Factory();
     if ($max->compare(PHP_INT_MAX) != 1 && $min->compare(PHP_INT_MIN) != -1 && $difference->compare(PHP_INT_MAX) != 1) {
         $x = $randFactory->getMediumStrengthGenerator()->generateInt($min, $max);
         return Numbers::makeFromBase10($this->numberType, $x, null, $this->contextBase);
     } else {
         $x = $randFactory->getMediumStrengthGenerator()->generateInt();
         $fraction = BCProvider::divide($x, PHP_INT_MAX);
         $addedValue = BCProvider::multiply($fraction, $difference->getValue());
         $randVal = Numbers::makeFromBase10($this->numberType, BCProvider::add($min->getValue(), $addedValue), null, $this->contextBase);
         return $randVal->round();
     }
 }
开发者ID:JordanRL,项目名称:Fermat,代码行数:28,代码来源:UniformContext.php

示例9: RandomLib

 function __construct()
 {
     parent::__construct();
     $factory = new RandomLib();
     $this->RandomLib = $factory->getMediumStrengthGenerator();
     $this->load->module('template');
     $this->load->module('categories');
 }
开发者ID:karsanrichard,项目名称:zerotech,代码行数:8,代码来源:MY_Controller.php

示例10: generateLink

 public static function generateLink($event)
 {
     $model = $event->getModel();
     if (!$model->link) {
         $factory = new Factory();
         $generator = $factory->getMediumStrengthGenerator();
         $model->link = $generator->generateString(32, Generator::CHAR_ALNUM);
     }
 }
开发者ID:idealistsoft,项目名称:framework-auth,代码行数:9,代码来源:UserLink.php

示例11: getAlternativeGenerator

 public function getAlternativeGenerator()
 {
     if (isset($this->generator)) {
         return $this->generator;
     }
     $factory = new RandomLib\Factory();
     $this->generator = $factory->getMediumStrengthGenerator();
     return $this->generator;
 }
开发者ID:Aasit,项目名称:DISCOUNT--SRV-I,代码行数:9,代码来源:RandomUtils.php

示例12: getAlternativeGenerator

 public function getAlternativeGenerator()
 {
     if (isset($this->generator)) {
         return $this->generator;
     }
     $factory = new RandomLib\Factory();
     $factory->registerSource('HashTiming', '\\SecurityMultiTool\\Random\\Source\\HashTiming');
     $this->generator = $factory->getMediumStrengthGenerator();
     return $this->generator;
 }
开发者ID:emma5021,项目名称:toba,代码行数:10,代码来源:Generator.php

示例13: testGetMediumStrengthGenerator

 /**
  * @covers RandomLib\Factory::getMediumStrengthGenerator
  * @covers RandomLib\Factory::getGenerator
  * @covers RandomLib\Factory::findMixer
  * @covers RandomLib\Factory::findSources
  */
 public function testGetMediumStrengthGenerator()
 {
     $factory = new Factory();
     $generator = $factory->getMediumStrengthGenerator();
     $this->assertTrue($generator instanceof Generator);
     $mixer = call_user_func(array(get_class($generator->getMixer()), 'getStrength'));
     $this->assertTrue($mixer->compare(new Strength(Strength::MEDIUM)) <= 0);
     foreach ($generator->getSources() as $source) {
         $strength = call_user_func(array(get_class($source), 'getStrength'));
         $this->assertTrue($strength->compare(new Strength(Strength::MEDIUM)) >= 0);
     }
 }
开发者ID:dukt,项目名称:craft-oauth,代码行数:18,代码来源:FactoryTest.php

示例14: getAlternativeGenerator

 /**
  * Retrieve a fallback/alternative RNG generator
  *
  * @return RandomLib\Generator
  */
 public static function getAlternativeGenerator()
 {
     if (null !== static::$generator) {
         return static::$generator;
     }
     if (!class_exists('RandomLib\\Factory')) {
         throw new Exception\RuntimeException('The RandomLib fallback pseudorandom number generator (PRNG) ' . ' must be installed in the absence of the OpenSSL and ' . 'Mcrypt extensions');
     }
     $factory = new RandomLib\Factory();
     $factory->registerSource('HashTiming', 'Zend\\Math\\Source\\HashTiming');
     static::$generator = $factory->getMediumStrengthGenerator();
     return static::$generator;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:18,代码来源:Rand.php

示例15: login

 public function login(Request $request, Response $response, array $arguments)
 {
     $body = $request->getParsedBody();
     $user = User::where('email', $body['email'])->first();
     if (!$user) {
         return $response->withJson(['message' => 'no_such_email'], 400);
     }
     if (!password_verify($body['password'], $user->password)) {
         return $response->withJson(['message' => 'incorrect_password'], 400);
     }
     $factory = new Factory();
     $generator = $factory->getMediumStrengthGenerator();
     $tokenValue = $generator->generateString(128, Generator::CHAR_ALNUM);
     $token = new UserToken();
     $token->value = $tokenValue;
     $user->user_tokens()->save($token);
     $output = ['user' => $user, 'token' => $token->value];
     return $response->withJson($output, 200);
 }
开发者ID:joppuyo,项目名称:Dullahan,代码行数:19,代码来源:UserController.php


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