當前位置: 首頁>>代碼示例>>PHP>>正文


PHP RandomGenerator類代碼示例

本文整理匯總了PHP中RandomGenerator的典型用法代碼示例。如果您正苦於以下問題:PHP RandomGenerator類的具體用法?PHP RandomGenerator怎麽用?PHP RandomGenerator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了RandomGenerator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的RandomGenerator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。