randInteger() public static method

Return a random integer between $min and $max
public static randInteger ( integer $min, integer $max, boolean $strong = false ) : integer
$min integer
$max integer
$strong boolean
return integer
Esempio n. 1
0
 /**
  * _srand() interception
  *
  * @see ZF-8742
  */
 protected function _srand()
 {
     if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
         return;
     }
     if (!self::$_srandCalled) {
         srand(Zend_Crypt_Math::randInteger(0, PHP_INT_MAX));
         self::$_srandCalled = true;
     }
 }
Esempio n. 2
0
 /**
  * Filters the HTTP requests being sent to add the Authorization header.
  *
  * If both AuthSub and ClientLogin tokens are set,
  * AuthSub takes precedence.  If an AuthSub key is set, then
  * secure AuthSub authentication is used, and the request is signed.
  * Requests must be signed only with the private key corresponding to the
  * public key registered with Google.  If an AuthSub key is set, but
  * openssl support is not enabled in the PHP installation, an exception is
  * thrown.
  *
  * @param string $method The HTTP method
  * @param string $url The URL
  * @param array $headers An associate array of headers to be
  *                       sent with the request or null
  * @param string $body The body of the request or null
  * @param string $contentType The MIME content type of the body or null
  * @throws Zend_Gdata_App_Exception if there was a signing failure
  * @return array The processed values in an associative array,
  *               using the same names as the params
  */
 public function filterHttpRequest($method, $url, $headers = array(), $body = null, $contentType = null)
 {
     if ($this->getAuthSubToken() != null) {
         // AuthSub authentication
         if ($this->getAuthSubPrivateKeyId() != null) {
             // secure AuthSub
             $time = time();
             $nonce = Zend_Crypt_Math::randInteger(0, 999999999);
             $dataToSign = $method . ' ' . $url . ' ' . $time . ' ' . $nonce;
             // compute signature
             $pKeyId = $this->getAuthSubPrivateKeyId();
             $signSuccess = openssl_sign($dataToSign, $signature, $pKeyId, OPENSSL_ALGO_SHA1);
             if (!$signSuccess) {
                 // require_once 'Zend/Gdata/App/Exception.php';
                 throw new Zend_Gdata_App_Exception('openssl_signing failure - returned false');
             }
             // encode signature
             $encodedSignature = base64_encode($signature);
             // final header
             $headers['authorization'] = 'AuthSub token="' . $this->getAuthSubToken() . '" ' . 'data="' . $dataToSign . '" ' . 'sig="' . $encodedSignature . '" ' . 'sigalg="rsa-sha1"';
         } else {
             // AuthSub without secure tokens
             $headers['authorization'] = 'AuthSub token="' . $this->getAuthSubToken() . '"';
         }
     } elseif ($this->getClientLoginToken() != null) {
         $headers['authorization'] = 'GoogleLogin auth=' . $this->getClientLoginToken();
     }
     return array('method' => $method, 'url' => $url, 'body' => $body, 'headers' => $headers, 'contentType' => $contentType);
 }
Esempio n. 3
0
 /**
  * Generate new random word
  *
  * @return string
  */
 protected function _generateWord()
 {
     $word = '';
     $wordLen = $this->getWordLen();
     $vowels = $this->_useNumbers ? self::$VN : self::$V;
     $consonants = $this->_useNumbers ? self::$CN : self::$C;
     $totIndexCon = count($consonants) - 1;
     $totIndexVow = count($vowels) - 1;
     for ($i = 0; $i < $wordLen; $i = $i + 2) {
         // generate word with mix of vowels and consonants
         $consonant = $consonants[Zend_Crypt_Math::randInteger(0, $totIndexCon, true)];
         $vowel = $vowels[Zend_Crypt_Math::randInteger(0, $totIndexVow, true)];
         $word .= $consonant . $vowel;
     }
     if (strlen($word) > $wordLen) {
         $word = substr($word, 0, $wordLen);
     }
     return $word;
 }