本文整理汇总了PHP中RandomGenerator::randomToken方法的典型用法代码示例。如果您正苦于以下问题:PHP RandomGenerator::randomToken方法的具体用法?PHP RandomGenerator::randomToken怎么用?PHP RandomGenerator::randomToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RandomGenerator
的用法示例。
在下文中一共展示了RandomGenerator::randomToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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');
}
}
示例2: 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;
}
示例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;
}
示例4: onBeforeWrite
protected function onBeforeWrite()
{
if (!$this->isInDB()) {
$generator = new RandomGenerator();
$this->Token = $generator->randomToken();
}
parent::onBeforeWrite();
}
示例5: generateConfirmationToken
/**
* @return string
*/
public function generateConfirmationToken()
{
$generator = new RandomGenerator();
$token = $generator->randomToken();
$hash = self::HashConfirmationToken($token);
$this->setField('ConfirmationHash', $hash);
return $token;
}
示例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;
}
示例7: 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;
}
示例8: 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;
}
示例9: onBeforeWrite
protected function onBeforeWrite()
{
if (!$this->isInDB()) {
$generator = new RandomGenerator();
$this->Token = $generator->randomToken();
if ($this->getManagerEmail()) {
$this->sendEmail();
}
}
parent::onBeforeWrite();
}
示例10: 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');
}
}
示例11: 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;
}
示例12: 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;
}
示例13: 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);
}
示例14: generate
/**
* @uses RandomGenerator
*
* @return String
*/
protected function generate()
{
$generator = new RandomGenerator();
return $generator->randomToken('sha1');
}
示例15: 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);
}