randBytes() public static méthode

Return a random strings of $length bytes
public static randBytes ( integer $length, boolean $strong = false ) : string
$length integer
$strong boolean
Résultat string
Exemple #1
0
 /**
  * Generate CSRF token
  *
  * Generates CSRF token and stores both in {@link $_hash} and element
  * value.
  *
  * @return void
  */
 protected function _generateHash()
 {
     $this->_hash = md5(Zend_Crypt_Math::randBytes(32));
     $this->setValue($this->_hash);
 }
 /**
  * Creates a LDAP password.
  *
  * @param  string $password
  * @param  string $hashType
  * @return string
  */
 public static function createPassword($password, $hashType = self::PASSWORD_HASH_MD5)
 {
     switch ($hashType) {
         case self::PASSWORD_UNICODEPWD:
             /* see:
              * http://msdn.microsoft.com/en-us/library/cc223248(PROT.10).aspx
              */
             $password = '******' . $password . '"';
             if (function_exists('mb_convert_encoding')) {
                 $password = mb_convert_encoding($password, 'UTF-16LE', 'UTF-8');
             } else {
                 if (function_exists('iconv')) {
                     $password = iconv('UTF-8', 'UTF-16LE', $password);
                 } else {
                     $len = strlen($password);
                     $new = '';
                     for ($i = 0; $i < $len; $i++) {
                         $new .= $password[$i] . "";
                     }
                     $password = $new;
                 }
             }
             return $password;
         case self::PASSWORD_HASH_SSHA:
             $salt = Zend_Crypt_Math::randBytes(4);
             $rawHash = sha1($password . $salt, true) . $salt;
             $method = '{SSHA}';
             break;
         case self::PASSWORD_HASH_SHA:
             $rawHash = sha1($password, true);
             $method = '{SHA}';
             break;
         case self::PASSWORD_HASH_SMD5:
             $salt = Zend_Crypt_Math::randBytes(4);
             $rawHash = md5($password . $salt, true) . $salt;
             $method = '{SMD5}';
             break;
         case self::PASSWORD_HASH_MD5:
         default:
             $rawHash = md5($password, true);
             $method = '{MD5}';
             break;
     }
     return $method . base64_encode($rawHash);
 }
 /**
  * Produces string of random byte of given length.
  *
  * @param integer $len length of requested string
  * @return string RAW random binary string
  */
 public static function randomBytes($len)
 {
     return (string) Zend_Crypt_Math::randBytes($len);
 }
Exemple #4
0
 protected function _generateRandomId()
 {
     return md5(Zend_Crypt_Math::randBytes(32));
 }