コード例 #1
0
ファイル: deleteActions.php プロジェクト: kzfk/emlauncher
 public function executeDelete_confirm()
 {
     $token = Random::string(32);
     mfwSession::set(self::SESKEY_TOKEN, $token);
     $parma = array('token' => $token);
     return $this->build($parma);
 }
コード例 #2
0
ファイル: installActions.php プロジェクト: kzfk/emlauncher
 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;
 }
コード例 #3
0
ファイル: Password.php プロジェクト: hossy78/nora
 /**
  * ランダムパスワードを生成する
  *
  * @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 = []);
 }
コード例 #4
0
ファイル: actions.php プロジェクト: kzfk/emlauncher
 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);
 }
コード例 #5
0
 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);
 }
コード例 #6
0
ファイル: PuTTY.php プロジェクト: phpseclib/phpseclib
 /**
  * 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;
 }
コード例 #7
0
$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()) {
コード例 #8
0
ファイル: rsa.php プロジェクト: sumit-aartek/foodkonnekt
 /**
  * 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);
 }
コード例 #9
0
 function rand_string($length = 10)
 {
     return Random::string($length, 'ABCDEFGHKLMNOPQRSTWXYZabcdefghjkmnpqrstwxyz');
 }
コード例 #10
0
ファイル: Application.php プロジェクト: kzfk/emlauncher
 public static function makeApiKey()
 {
     do {
         $api_key = Random::string();
     } while (static::selectByApiKey($api_key));
     return $api_key;
 }
コード例 #11
0
ファイル: Package.php プロジェクト: kzfk/emlauncher
 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;
 }