예제 #1
0
 public function testPronounceablePwd()
 {
     $is = Random::pronounceablePwd(6);
     //pr($is);
     $this->assertTrue(strlen($is) === 6);
     $is = Random::pronounceablePwd(11);
     //pr($is);
     $this->assertTrue(strlen($is) === 11);
 }
예제 #2
0
 /**
  * Generator of secure random tokens.
  *
  * Note that it is best to use an even number for the length.
  *
  * @param int|null $length (defaults to defaultLength)
  * @return string Key
  */
 public function generateKey($length = null)
 {
     if (empty($length)) {
         $length = $this->defaultLength;
     }
     if (version_compare(PHP_VERSION, '7.0.0') >= 0) {
         $function = 'random_bytes';
     } elseif (extension_loaded('openssl')) {
         $function = 'openssl_random_pseudo_bytes';
     } else {
         trigger_error('Not secure', E_USER_DEPRECATED);
         return Random::pwd($length);
     }
     $value = bin2hex($function($length / 2));
     if (strlen($value) !== $length) {
         $value = str_pad($value, $length, '0');
     }
     return $value;
 }
예제 #3
0
 /**
  * Generator
  *
  * @param length (defaults to defaultLength)
  * @return string Key
  */
 public function generateKey($length = null)
 {
     if (empty($length)) {
         $length = $this->defaultLength;
     }
     return Random::pwd($length);
 }