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


PHP Random::string方法代码示例

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


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

示例1: executeDelete_confirm

 public function executeDelete_confirm()
 {
     $token = Random::string(32);
     mfwSession::set(self::SESKEY_TOKEN, $token);
     $parma = array('token' => $token);
     return $this->build($parma);
 }
开发者ID:kzfk,项目名称:emlauncher,代码行数:7,代码来源:deleteActions.php

示例2: makeToken

 protected function makeToken()
 {
     $pkg_id = $this->package->getId();
     $token = Random::string(32);
     // tokenは60秒有効
     mfwMemcache::set(self::TOKEN_KEY_PREFIX . $token, $pkg_id, 60);
     return $token;
 }
开发者ID:kzfk,项目名称:emlauncher,代码行数:8,代码来源:installActions.php

示例3: generate

 /**
  * ランダムパスワードを生成する
  *
  * @param int
  * @param array
  * @return string
  */
 public static function generate($length = 8, $chars = ['-', '_', '.', '$', '#', '%'])
 {
     if ($length < 4) {
         throw new \Exception('パスワードが短すぎます');
     }
     $password = Random::string($length, $chars);
     // 強度のテスト 大文字,小文字,数字,記号の混在
     // 先頭,記号,数字不可
     if (preg_match('/[A-Z]/', $password) && preg_match('/[a-z]/', $password) && preg_match('/[0-9]/', $password) && preg_match('/^[A-Za-z]/', $password)) {
         return $password;
     }
     return self::generate($length, $chars = []);
 }
开发者ID:hossy78,项目名称:nora,代码行数:20,代码来源:Password.php

示例4: executeCreate_token

 public function executeCreate_token()
 {
     $token_expire = '+1 hours';
     $expire_time = strtotime($token_expire);
     $mc_expire = $expire_time - time();
     $tokendata = array('mail' => $this->login_user->getMail(), 'package_id' => $this->package->getId(), 'expire' => date('Y-m-d H:i:s', $expire_time));
     $token = Random::string(32);
     mfwMemcache::set(self::INSTALL_TOKEN_PREFIX . $token, json_encode($tokendata), $mc_expire);
     apache_log('token', $token);
     apache_log('token_data', $tokendata);
     $params = array('token' => $token, 'expire' => $tokendata['expire'], 'token_url' => mfwRequest::makeURL("/package/install?token={$token}"));
     return $this->build($params);
 }
开发者ID:kzfk,项目名称:emlauncher,代码行数:13,代码来源:actions.php

示例5: executeCreate_token

 public function executeCreate_token()
 {
     try {
         $api_key = mfwRequest::param('api_key');
         $pkg_id = mfwRequest::param('id');
         $mail = mfwRequest::param('mail');
         $expire_hour = mfwRequest::param('expire_hour');
         // api_key check
         $app = ApplicationDb::selectByApiKey($api_key);
         if (!$app) {
             return $this->jsonResponse(self::HTTP_400_BADREQUEST, array('error' => 'Invalid api_key'));
         }
         // id check
         $pkg = PackageDb::retrieveByPK($pkg_id);
         if (!$pkg || $app->getId() !== $pkg->getAppId()) {
             return $this->jsonResponse(self::HTTP_400_BADREQUEST, array('error' => 'Invalid package id'));
         }
         // mail check
         $owner_mails = $app->getOwners()->getMailArray();
         if (!in_array($mail, $owner_mails)) {
             return $this->jsonResponse(self::HTTP_400_BADREQUEST, array('error' => 'Invalid mail address'));
         }
         // create install token
         $expire_hour = empty($expire_hour) ? 1 : $expire_hour;
         $token_expire = sprintf('+%s hours', $expire_hour);
         $expire_time = strtotime($token_expire);
         $mc_expire = $expire_time - time();
         $tokendata = array('mail' => $mail, 'package_id' => $pkg_id, 'expire' => date('Y-m-d H:i:s', $expire_time));
         $token = Random::string(32);
         mfwMemcache::set(self::INSTALL_TOKEN_PREFIX . $token, json_encode($tokendata), $mc_expire);
         apache_log('token', $token);
         apache_log('token_data', $tokendata);
         $ret = $this->makePackageArray($pkg);
         $ret['install_url'] = mfwRequest::makeURL("/package/install?token={$token}");
     } catch (Exception $e) {
         error_log(__METHOD__ . '(' . __LINE__ . '): ' . get_class($e) . ":{$e->getMessage()}");
         return $this->jsonResponse(self::HTTP_500_INTERNALSERVERERROR, array('error' => $e->getMessage(), 'exception' => get_class($e)));
     }
     apache_log('app_id', $app->getId());
     return $this->jsonResponse(self::HTTP_200_OK, $ret);
 }
开发者ID:kzfk,项目名称:emlauncher,代码行数:41,代码来源:create_tokenAction.php

示例6: savePrivateKey

 /**
  * Convert a private key to the appropriate format.
  *
  * @access public
  * @param \phpseclib\Math\BigInteger $n
  * @param \phpseclib\Math\BigInteger $e
  * @param \phpseclib\Math\BigInteger $d
  * @param array $primes
  * @param array $exponents
  * @param array $coefficients
  * @param string $password optional
  * @return string
  */
 static function savePrivateKey(BigInteger $n, BigInteger $e, BigInteger $d, $primes, $exponents, $coefficients, $password = '')
 {
     if (count($primes) != 2) {
         return false;
     }
     $raw = array('modulus' => $n->toBytes(true), 'publicExponent' => $e->toBytes(true), 'privateExponent' => $d->toBytes(true), 'prime1' => $primes[1]->toBytes(true), 'prime2' => $primes[2]->toBytes(true), 'exponent1' => $exponents[1]->toBytes(true), 'exponent2' => $exponents[2]->toBytes(true), 'coefficient' => $coefficients[2]->toBytes(true));
     $key = "PuTTY-User-Key-File-2: ssh-rsa\r\nEncryption: ";
     $encryption = !empty($password) || is_string($password) ? 'aes256-cbc' : 'none';
     $key .= $encryption;
     $key .= "\r\nComment: " . self::$comment . "\r\n";
     $public = pack('Na*Na*Na*', strlen('ssh-rsa'), 'ssh-rsa', strlen($raw['publicExponent']), $raw['publicExponent'], strlen($raw['modulus']), $raw['modulus']);
     $source = pack('Na*Na*Na*Na*', strlen('ssh-rsa'), 'ssh-rsa', strlen($encryption), $encryption, strlen(self::$comment), self::$comment, strlen($public), $public);
     $public = Base64::encode($public);
     $key .= "Public-Lines: " . (strlen($public) + 63 >> 6) . "\r\n";
     $key .= chunk_split($public, 64);
     $private = pack('Na*Na*Na*Na*', strlen($raw['privateExponent']), $raw['privateExponent'], strlen($raw['prime1']), $raw['prime1'], strlen($raw['prime2']), $raw['prime2'], strlen($raw['coefficient']), $raw['coefficient']);
     if (empty($password) && !is_string($password)) {
         $source .= pack('Na*', strlen($private), $private);
         $hashkey = 'putty-private-key-file-mac-key';
     } else {
         $private .= Random::string(16 - (strlen($private) & 15));
         $source .= pack('Na*', strlen($private), $private);
         $crypto = new AES();
         $crypto->setKey(static::generateSymmetricKey($password, 32));
         $crypto->setIV(str_repeat("", $crypto->getBlockLength() >> 3));
         $crypto->disablePadding();
         $private = $crypto->encrypt($private);
         $hashkey = 'putty-private-key-file-mac-key' . $password;
     }
     $private = Base64::encode($private);
     $key .= 'Private-Lines: ' . (strlen($private) + 63 >> 6) . "\r\n";
     $key .= chunk_split($private, 64);
     $hash = new Hash('sha1');
     $hash->setKey(sha1($hashkey, true));
     $key .= 'Private-MAC: ' . Hex::encode($hash->hash($source)) . "\r\n";
     return $key;
 }
开发者ID:phpseclib,项目名称:phpseclib,代码行数:50,代码来源:PuTTY.php

示例7: bin2hex

$my_random_boolean = Random::boolean() ? 1 : 0;
$result_true = 0;
$result_false = 0;
for ($i = 1; $i <= 100; $i++) {
    if (Random::boolean()) {
        $result_true++;
    } else {
        $result_false++;
    }
}
$my_random_bytes = bin2hex(Random::bytes(10));
$my_random_float = Random::float();
$my_random_integer = Random::int(0, PHP_INT_MAX);
$my_random_integer_2 = Random::int(1, 100);
$my_random_string = Random::string(20);
$my_random_string_2 = Random::string(20, "!\"#\$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~");
?>
                        <table class="table table-bordered" style="table-layout: fixed; word-wrap: break-word;">
                            <tbody>
                                <tr>
                                    <td style="width: 50%;"><pre><code>$my_random_boolean = Random::boolean() ? 1 : 0;</code></pre></td>
                                    <td><?php 
echo $my_random_boolean;
?>
</td>
                                </tr>
                                <tr>
                                    <td><pre><code>$result_true = 0;
$result_false = 0;
for ($i = 1; $i <= 100; $i++) {
    if (Random::boolean()) {
开发者ID:Qnatz,项目名称:starter-public-edition-4,代码行数:31,代码来源:random.php

示例8: _random_number_helper

 /**
  * Generates a random BigInteger
  *
  * Byte length is equal to $length. Uses \phpseclib\Crypt\Random if it's loaded and mt_rand if it's not.
  *
  * @param Integer $length
  * @return \phpseclib\Math\BigInteger
  * @access private
  */
 function _random_number_helper($size)
 {
     if (class_exists('\\phpseclib\\Crypt\\Random')) {
         $random = Random::string($size);
     } else {
         $random = '';
         if ($size & 1) {
             $random .= chr(mt_rand(0, 255));
         }
         $blocks = $size >> 1;
         for ($i = 0; $i < $blocks; ++$i) {
             // mt_rand(-2147483648, 0x7FFFFFFF) always produces -2147483648 on some systems
             $random .= pack('n', mt_rand(0, 0xffff));
         }
     }
     return new static($random, 256);
 }
开发者ID:sumit-aartek,项目名称:foodkonnekt,代码行数:26,代码来源:rsa.php

示例9: rand_string

 function rand_string($length = 10)
 {
     return Random::string($length, 'ABCDEFGHKLMNOPQRSTWXYZabcdefghjkmnpqrstwxyz');
 }
开发者ID:Qnatz,项目名称:starter-public-edition-4,代码行数:4,代码来源:MY_string_helper.php

示例10: makeApiKey

 public static function makeApiKey()
 {
     do {
         $api_key = Random::string();
     } while (static::selectByApiKey($api_key));
     return $api_key;
 }
开发者ID:kzfk,项目名称:emlauncher,代码行数:7,代码来源:Application.php

示例11: insertNewPackage

 public static function insertNewPackage($app_id, $platform, $ext, $title, $description, $ios_identifier, $org_file_name, $file_size, TagSet $tags, $con)
 {
     $row = array('app_id' => $app_id, 'platform' => $platform, 'file_name' => Random::string(16) . ".{$ext}", 'title' => $title, 'description' => $description, 'ios_identifier' => $ios_identifier, 'original_file_name' => $org_file_name, 'file_size' => $file_size, 'created' => date('Y-m-d H:i:s'));
     $pkg = new Package($row);
     $pkg->insert($con);
     $pkg->initTags($tags, $con);
     return $pkg;
 }
开发者ID:kzfk,项目名称:emlauncher,代码行数:8,代码来源:Package.php


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