• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP RandomGenerator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: onBeforeWrite

 public function onBeforeWrite()
 {
     if (!$this->owner->NewsletterTrackingToken) {
         $generator = new RandomGenerator();
         $this->owner->NewsletterTrackingToken = $generator->generateHash('md5');
     }
 }
开发者ID:nyeholt,项目名称:silverstripe-newsletter-tracking,代码行数:7,代码来源:NewsletterTrackingMemberExtension.php


示例2: onBeforeWrite

 /**
  * Ensure we populate these fields before a save.
  */
 public function onBeforeWrite()
 {
     // Run other beforewrites first.
     parent::onBeforeWrite();
     if (!$this->isBrowser()) {
         return false;
     }
     // If this is the first save...
     if (!$this->ID) {
         // Ensure the session exists before querying it.
         if (!Session::request_contains_session_id()) {
             Session::start();
         }
         // Store the sesion and has information in the database.
         $this->SessionID = SecurityToken::getSecurityID();
         if (is_null($this->SessionID)) {
             return false;
         }
         $gen = new RandomGenerator();
         $uniqueurl = substr($gen->randomToken(), 0, 32);
         while (ShortList::get()->filter('URL', $uniqueurl)->count() > 0) {
             $uniqueurl = substr($gen->randomToken(), 0, 32);
         }
         $this->URL = $uniqueurl;
         $this->UserAgent = Controller::curr()->getRequest()->getHeader('User-Agent');
     }
 }
开发者ID:salted-herring,项目名称:silverstripe-shortlist,代码行数:30,代码来源:ShortList.php


示例3: generateOneTime

 /**
  * Generates the One Time code that is passed to the redirect URL as GET param ott
  * Supports extension via extendGenerateOneTime, with a max token length of 255
  */
 public function generateOneTime()
 {
     $randomGen = new RandomGenerator();
     $random = substr($randomGen->randomToken(), 0, 10);
     $this->extend('extendGenerateOneTime', $random);
     $this->OneTimeCode = $random;
 }
开发者ID:Marketo,项目名称:SilverStripe-Authorized-Redirects,代码行数:11,代码来源:Authorization.php


示例4: onBeforeWrite

 protected function onBeforeWrite()
 {
     if (!$this->isInDB()) {
         $generator = new RandomGenerator();
         $this->Token = $generator->randomToken();
     }
     parent::onBeforeWrite();
 }
开发者ID:tim-lar,项目名称:silverstripe-eventmanagement,代码行数:8,代码来源:EventRegistration.php


示例5: generateConfirmationToken

 /**
  * @return string
  */
 public function generateConfirmationToken()
 {
     $generator = new RandomGenerator();
     $token = $generator->randomToken();
     $hash = self::HashConfirmationToken($token);
     $this->setField('ConfirmationHash', $hash);
     return $token;
 }
开发者ID:OpenStackweb,项目名称:openstack-org,代码行数:11,代码来源:TeamInvitation.php


示例6: generate_token

 /**
  * Generates an encrypted random token.
  * @param \Member $user
  * @throws \PasswordEncryptor_NotFoundException
  * @return string
  */
 public static function generate_token($user)
 {
     $generator = new \RandomGenerator();
     $tokenString = $generator->randomToken();
     $e = \PasswordEncryptor::create_for_algorithm('blowfish');
     $salt = $e->salt($tokenString);
     $token = sha1($e->encrypt($tokenString, $salt)) . substr(md5($user->Created . $user->LastEdited . $user->ID), 7);
     return $token;
 }
开发者ID:notthatbad,项目名称:silverstripe-rest-api,代码行数:15,代码来源:AuthFactory.php


示例7: generateTokens

 /**
  * Generate and store the authentication tokens required
  * 
  * @TODO Rework this, it's not really any better than storing text passwords
  */
 public function generateTokens()
 {
     $generator = new RandomGenerator();
     $token = $generator->randomToken('sha1');
     $this->owner->Token = $this->owner->encryptWithUserSettings($token);
     $this->authToken = $token;
     $authToken = $generator->randomToken('whirlpool');
     $this->owner->AuthPrivateKey = $authToken;
 }
开发者ID:helpfulrobot,项目名称:silverstripe-webservices,代码行数:14,代码来源:TokenAccessible.php


示例8: generateConfirmationToken

 /**
  * @return string
  */
 public function generateConfirmationToken()
 {
     $generator = new RandomGenerator();
     $this->token = $generator->randomToken();
     $hash = self::HashConfirmationToken($this->token);
     $this->setField('ConfirmationHash', $hash);
     Session::set(self::ConfirmationTokenParamName . '_' . $this->Speaker()->ID, $this->token);
     return $this->token;
 }
开发者ID:balajijegan,项目名称:openstack-org,代码行数:12,代码来源:SpeakerRegistrationRequest.php


示例9: genToken

 protected function genToken()
 {
     // Generate a new random token (as random as possible)
     require_once dirname(dirname(dirname(__FILE__))) . '/security/RandomGenerator.php';
     $rg = new RandomGenerator();
     $token = $rg->randomToken('md5');
     // Store a file in the session save path (safer than /tmp, as open_basedir might limit that)
     file_put_contents($this->pathForToken($token), $token);
     return $token;
 }
开发者ID:congaaids,项目名称:silverstripe-framework,代码行数:10,代码来源:ParameterConfirmationToken.php


示例10: onBeforeWrite

 protected function onBeforeWrite()
 {
     if (!$this->isInDB()) {
         $generator = new RandomGenerator();
         $this->Token = $generator->randomToken();
         if ($this->getManagerEmail()) {
             $this->sendEmail();
         }
     }
     parent::onBeforeWrite();
 }
开发者ID:tardinha,项目名称:silverstripe-eventmanagement,代码行数:11,代码来源:EventRegistration.php


示例11: onBeforeWrite

 function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if (!$this->ValidUntil) {
         $this->setValidInMinutesFromNow();
     }
     if (!$this->RequestedFromIP) {
         $this->RequestedFromIP = $_SERVER['REMOTE_ADDR'];
     }
     if (!$this->UID) {
         $generator = new RandomGenerator();
         $this->UID = $generator->randomToken('sha1');
     }
 }
开发者ID:helpfulrobot,项目名称:pstaender-silverstripe-restful-api,代码行数:14,代码来源:AuthSession.php


示例12: generateConfirmationToken

 /**
  * @return string
  */
 public function generateConfirmationToken()
 {
     $generator = new RandomGenerator();
     $already_exists = false;
     $repository = new SapphireSpeakerRegistrationRequestRepository();
     do {
         $this->token = $generator->randomToken();
         $already_exists = $repository->existsConfirmationToken($this->token);
     } while ($already_exists);
     $hash = self::HashConfirmationToken($this->token);
     $this->setField('ConfirmationHash', $hash);
     Session::set(self::ConfirmationTokenParamName . '_' . $this->Speaker()->ID, $this->token);
     return $this->token;
 }
开发者ID:OpenStackweb,项目名称:openstack-org,代码行数:17,代码来源:SpeakerRegistrationRequest.php


示例13: doFlag

 /**
  * Flags the current comment
  *
  * @return bool
  */
 public function doFlag()
 {
     if (!$this->owner->canFlag()) {
         return false;
     }
     $this->owner->Flagged = true;
     $this->owner->FlaggedAndRemoved = false;
     $random = new RandomGenerator();
     $this->owner->FlaggedSecurityToken = $random->randomToken();
     try {
         $this->owner->write();
     } catch (ValidationException $e) {
         SS_Log::log($e->getMessage(), SS_Log::WARN);
         return false;
     }
     $this->owner->extend('afterFlag');
     return true;
 }
开发者ID:micmania1,项目名称:silverstripe-flagcomments,代码行数:23,代码来源:FlagCommentExtension.php


示例14: testMany

 public function testMany()
 {
     $output = RandomGenerator::generate();
     $this->assertFalse(is_array($output), 'Output is array');
     $this->assertRegExp('/^([a-zA-Z0-9]{10})$/', $output, 'Single match not ok');
     $output = RandomGenerator::generate(3, 120, RandomGenerator::TYPE_ALPHANUM, 'start:X:end', 8, '-');
     $this->assertTrue(is_array($output), 'Not array');
     if (is_array($output)) $this->assertEquals(count($output), 3, 'Array count not 3');
     foreach ($output as $out) {
         $this->assertRegExp('/^start:([a-zA-Z0-9-]{134}):end$/', $out, 'Element not ok');
     }
 }
开发者ID:haegyung,项目名称:xe-module-shop,代码行数:12,代码来源:RandomGeneratorTest.php


示例15: testSecurityID

 /**
  * Tests security ID check
  */
 public function testSecurityID()
 {
     // Mock token
     $securityToken = SecurityToken::inst();
     $generator = new RandomGenerator();
     $token = $generator->randomToken('sha1');
     $session = array($securityToken->getName() => $token);
     $tokenError = _t('SpellController.SecurityMissing', 'Your session has expired. Please refresh your browser to continue.');
     // Test request sans token
     $response = $this->get('spellcheck', Injector::inst()->create('Session', $session));
     $this->assertEquals(400, $response->getStatusCode());
     $jsonBody = json_decode($response->getBody());
     $this->assertEquals($tokenError, $jsonBody->error->errstr);
     // Test request with correct token (will fail with an unrelated error)
     $response = $this->get('spellcheck/?SecurityID=' . urlencode($token), Injector::inst()->create('Session', $session));
     $jsonBody = json_decode($response->getBody());
     $this->assertNotEquals($tokenError, $jsonBody->error->errstr);
     // Test request with check disabled
     Config::inst()->update('SpellController', 'enable_security_token', false);
     $response = $this->get('spellcheck', Injector::inst()->create('Session', $session));
     $jsonBody = json_decode($response->getBody());
     $this->assertNotEquals($tokenError, $jsonBody->error->errstr);
 }
开发者ID:helpfulrobot,项目名称:silverstripe-spellcheck,代码行数:26,代码来源:SpellControllerTest.php


示例16: actionCreate

 public function actionCreate()
 {
     $model = new Clients();
     $account = new Accounts();
     $preference = new Preferences();
     if (isset($_POST['Clients'], $_POST['Accounts'], $_POST['Preferences'])) {
         $model->attributes = $_POST['Clients'];
         $account->attributes = $_POST['Accounts'];
         $preference->attributes = $_POST['Preferences'];
         $model->login_name = $account->login_name;
         $model->client_code = RandomGenerator::generateString(AdminGlobals::CLIENT_CODE_LENGTH);
         $model->subscription_status = "active";
         $preference->prepaid_passwd = RandomGenerator::generateString(AdminGlobals::PREPAID_PASSWD_LENGTH);
         $account->account_name = $model->client_name;
         $account->email = $model->email;
         $account->is_visible = 0;
         $valid = $model->validate();
         $valid = $account->validate() && $valid;
         $valid = $preference->validate() && $valid;
         if ($valid) {
             $transaction = Yii::app()->db->beginTransaction();
             $success = $model->save(false);
             if ($success) {
                 $account->client_id = $preference->client_id = $model->id;
             }
             $success = $success && $account->save(false);
             $success = $success && $preference->save(false);
             if ($success) {
                 $transaction->commit();
                 if (Yii::app()->request->isAjaxRequest) {
                     $this->renderPartial('view', array('model' => $this->loadModel($model->id), 'account' => $account, 'preference' => $preference), false, true);
                     Yii::app()->end();
                 }
                 $this->redirect(array('view', 'id' => $model->id));
             }
             $transaction->rollBack();
         }
     }
     if (Yii::app()->request->isAjaxRequest) {
         $this->renderPartial('create', array('model' => $model, 'account' => $account, 'preference' => $preference), false, true);
         Yii::app()->end();
     }
     $this->render('create', array('model' => $model, 'account' => $account, 'preference' => $preference));
 }
开发者ID:thehiddennepali,项目名称:Sample-Code,代码行数:44,代码来源:ClientsController.php


示例17: generateAutologinTokenAndStoreHash

 /**
  * Generate an auto login token which can be used to reset the password,
  * at the same time hashing it and storing in the database.
  *
  * @param int $lifetime The lifetime of the auto login hash in days (by default 2 days)
  *
  * @returns string Token that should be passed to the client (but NOT persisted).
  *
  * @todo Make it possible to handle database errors such as a "duplicate key" error
  */
 public function generateAutologinTokenAndStoreHash($lifetime = 2)
 {
     do {
         $generator = new RandomGenerator();
         $token = $generator->randomToken();
         $hash = $this->encryptWithUserSettings($token);
     } while (DataObject::get_one('Member', "\"AutoLoginHash\" = '{$hash}'"));
     $this->AutoLoginHash = $hash;
     $this->AutoLoginExpired = date('Y-m-d', time() + 86400 * $lifetime);
     $this->write();
     return $token;
 }
开发者ID:hemant-chakka,项目名称:awss,代码行数:22,代码来源:Member.php


示例18: header

<?php

include 'random-generator.class.php';
header('Content-Type: text/plain');
$seed = 12345;
$generator = new RandomGenerator($seed);
echo "seed : {$seed}\n";
for ($n = 0; $n < 100; $n++) {
    $value = $generator->random() % 100;
    echo "{$n} : {$value}\n";
}
开发者ID:GrayTap,项目名称:pseudo-random-generator-xor-shift,代码行数:11,代码来源:example-php.php


示例19: generateFilename

 /**
  * Returns a unique filename, including project/environment/timestamp details.
  * @return string
  */
 public function generateFilename(DNDataTransfer $dataTransfer)
 {
     $generator = new RandomGenerator();
     $filter = FileNameFilter::create();
     return sprintf('%s-%s-%s-%s-%s', $filter->filter(strtolower($this->OriginalEnvironment()->Project()->Name)), $filter->filter(strtolower($this->OriginalEnvironment()->Name)), $dataTransfer->Mode, date('Ymd'), sha1($generator->generateEntropy()));
 }
开发者ID:antons-,项目名称:deploynaut,代码行数:10,代码来源:DNDataArchive.php


示例20: generateToken

 /**
  * Generates an encrypted random token
  * and an expiry date
  * 
  * @param  boolean $expired Set to true to generate an outdated token
  * @return array            token data array('token' => HASH, 'expire' => EXPIRY_DATE)
  */
 private function generateToken($expired = false)
 {
     $life = $this->tokenConfig['life'];
     if (!$expired) {
         $expire = time() + $life;
     } else {
         $expire = time() - $life * 2;
     }
     $generator = new RandomGenerator();
     $tokenString = $generator->randomToken();
     $e = PasswordEncryptor::create_for_algorithm('blowfish');
     //blowfish isn't URL safe and maybe too long?
     $salt = $e->salt($tokenString);
     $token = $e->encrypt($tokenString, $salt);
     return array('token' => substr($token, 7), 'expire' => $expire);
 }
开发者ID:8secs,项目名称:cocina,代码行数:23,代码来源:RESTfulAPI_TokenAuthenticator.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP RangePrice类代码示例发布时间:2022-05-23
下一篇:
PHP Random类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap