本文整理汇总了PHP中MWCryptRand::generateHex方法的典型用法代码示例。如果您正苦于以下问题:PHP MWCryptRand::generateHex方法的具体用法?PHP MWCryptRand::generateHex怎么用?PHP MWCryptRand::generateHex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MWCryptRand
的用法示例。
在下文中一共展示了MWCryptRand::generateHex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute()
{
$user = $this->getUser();
$params = $this->extractRequestParams();
// If we're in JSON callback mode, no tokens can be obtained
if ($this->lacksSameOriginSecurity()) {
$this->dieUsage('Cannot obtain a centralauthtoken when using a callback', 'hascallback');
}
if ($user->isAnon()) {
$this->dieUsage('Anonymous users cannot obtain a centralauthtoken', 'notloggedin');
}
if (CentralAuthHooks::hasApiToken()) {
$this->dieUsage('Cannot obtain a centralauthtoken when using centralauthtoken', 'norecursion');
}
$centralUser = CentralAuthUser::getInstance($user);
if (!$centralUser->exists() || !$centralUser->isAttached()) {
$this->dieUsage('Cannot obtain a centralauthtoken without an attached global account', 'notattached');
}
$data = array('userName' => $user->getName(), 'token' => $centralUser->getAuthToken());
global $wgMemc;
$loginToken = MWCryptRand::generateHex(32) . dechex($centralUser->getId());
$key = CentralAuthUser::memcKey('api-token', $loginToken);
$wgMemc->add($key, $data, 60);
$this->getResult()->addValue(null, $this->getModuleName(), array('centralauthtoken' => $loginToken));
}
示例2: crypt
public function crypt($plaintext)
{
if (count($this->args) == 0) {
$this->args[] = MWCryptRand::generateHex(8);
}
$this->hash = md5($this->args[0] . '-' . md5($plaintext));
}
示例3: lqtThread
static function lqtThread($parser, $args, $parser, $frame)
{
$pout = $parser->getOutput();
// Prepare information.
$title = Title::newFromText($args['thread']);
$thread = null;
if ($args['thread']) {
if (is_numeric($args['thread'])) {
$thread = Threads::withId($args['thread']);
} elseif ($title) {
$article = new Article($title, 0);
$thread = Threads::withRoot($article);
}
}
if (is_null($thread)) {
return '';
}
$data = array('type' => 'thread', 'args' => $args, 'thread' => $thread->id(), 'title' => $thread->title());
if (!isset($pout->mLqtReplacements)) {
$pout->mLqtReplacements = array();
}
// Generate a token
$tok = MWCryptRand::generateHex(32);
$text = '<!--LQT-THREAD-' . $tok . '-->';
$pout->mLqtReplacements[$text] = $data;
return $text;
}
示例4: memcacheSave
/**
* Serialize and save data to memcache
*
* Note that it also sets a time to live for the
* cached version set to self::TTL
*
* @param string $cacheKey Cache key
* @param mixed $data Data to send to memcached, will use serialize();
*
* @return null
*/
private function memcacheSave($data)
{
$url_friendly_key = MWCryptRand::generateHex(16);
$key = wfMemcKey($url_friendly_key, 'wpdsso');
$this->memcache->set($key, json_encode($data), self::TTL);
return $url_friendly_key;
}
示例5: crypt
public function crypt($plaintext)
{
if (count($this->args) == 0) {
$this->args[] = MWCryptRand::generateHex(8);
}
$this->hash = md5($this->args[0] . '-' . md5($plaintext));
if (!is_string($this->hash) || strlen($this->hash) < 32) {
throw new PasswordError('Error when hashing password.');
}
}
示例6: setUp
protected function setUp()
{
// Needs to be before setup since this gets cached
$this->mergeMwGlobalArrayValue('wgGroupPermissions', array('sysop' => array('deleterevision' => true)));
parent::setUp();
// Make a few edits for us to play with
for ($i = 1; $i <= 5; $i++) {
self::editPage(self::$page, MWCryptRand::generateHex(10), 'summary');
$this->revs[] = Title::newFromText(self::$page)->getLatestRevID(Title::GAID_FOR_UPDATE);
}
}
示例7: getPreloadId
protected static function getPreloadId($create_if_not_exists)
{
global $wgUser, $wgRequest;
if (!$wgUser->isAnon()) {
return ModerationPreload::User_to_PreloadId($wgUser);
}
$anon_id = $wgRequest->getSessionData('anon_id');
if (!$anon_id) {
if (!$create_if_not_exists) {
return false;
}
$anon_id = MWCryptRand::generateHex(32);
$wgRequest->setSessionData('anon_id', $anon_id);
}
return ModerationPreload::AnonId_to_PreloadId($anon_id);
}
示例8: handleReauthBeforeExecute
/**
* Handle redirection when the user needs to (re)authenticate.
*
* Send the user to the login form if needed; in case the request was a POST, stash in the
* session and simulate it once the user gets back.
*
* @param string $subPage
* @return bool False if execution should be stopped.
* @throws ErrorPageError When the user is not allowed to use this page.
*/
protected function handleReauthBeforeExecute($subPage)
{
$authManager = AuthManager::singleton();
$request = $this->getRequest();
$key = 'AuthManagerSpecialPage:reauth:' . $this->getName();
$securityLevel = $this->getLoginSecurityLevel();
if ($securityLevel) {
$securityStatus = AuthManager::singleton()->securitySensitiveOperationStatus($securityLevel);
if ($securityStatus === AuthManager::SEC_REAUTH) {
$queryParams = array_diff_key($request->getQueryValues(), ['title' => true]);
if ($request->wasPosted()) {
// unique ID in case the same special page is open in multiple browser tabs
$uniqueId = MWCryptRand::generateHex(6);
$key = $key . ':' . $uniqueId;
$queryParams = ['authUniqueId' => $uniqueId] + $queryParams;
$authData = array_diff_key($request->getValues(), $this->getPreservedParams(false), ['title' => 1]);
$authManager->setAuthenticationSessionData($key, $authData);
}
$title = SpecialPage::getTitleFor('Userlogin');
$url = $title->getFullURL(['returnto' => $this->getFullTitle()->getPrefixedDBkey(), 'returntoquery' => wfArrayToCgi($queryParams), 'force' => $securityLevel], false, PROTO_HTTPS);
$this->getOutput()->redirect($url);
return false;
} elseif ($securityStatus !== AuthManager::SEC_OK) {
throw new ErrorPageError('cannotauth-not-allowed-title', 'cannotauth-not-allowed');
}
}
$uniqueId = $request->getVal('authUniqueId');
if ($uniqueId) {
$key = $key . ':' . $uniqueId;
$authData = $authManager->getAuthenticationSessionData($key);
if ($authData) {
$authManager->removeAuthenticationSessionData($key);
$this->setRequest($authData, true);
}
}
return true;
}
示例9: printFooterThings
private function printFooterThings()
{
// prepare login token:
$loginToken = MWCryptRand::generateHex(32);
if ($this->getSkin()->getTitle()->getText() != 'UserLogin') {
// Skin userlogin page to avoid collision
if (session_id() == '') {
wfSetupSession();
}
$this->getSkin()->getRequest()->setSessionData('wsLoginToken', $loginToken);
}
?>
<div class="why-sign-up-popup mobile-form-popup">
<h3>
<?php
echo wfMessage('settlein-skin-modal-whysignup-title')->plain();
?>
</h3>
<?php
echo wfMessage('settlein-skin-modal-whysignup-text')->plain();
?>
</div>
<!-- Login popup form & wrapper -->
<div id="login-popup-wrapper">
</div>
<div class="login-popup-form mobile-form-popup">
<h3>
<?php
echo wfMessage('settlein-skin-modal-login-title')->plain();
?>
</h3>
<p>
<?php
echo wfMessage('settlein-skin-modal-login-subtitle')->plain();
?>
</p>
<form class="" method="post" action="<?php
echo SpecialPage::getSafeTitleFor('UserLogin')->getFullURL('action=submitlogin&type=login');
?>
">
<div class="form-group">
<input type="text" class="form-control" placeholder="<?php
echo wfMessage('settlein-skin-modal-login-email-placeholder')->plain();
?>
" name="wpName" />
</div>
<div class="form-group">
<input type="password" class="form-control" placeholder="<?php
echo wfMessage('settlein-skin-modal-login-password-placeholder')->plain();
?>
" name="wpPassword" />
</div>
<input type="hidden" name="wpLoginToken" value="<?php
echo $loginToken;
?>
" />
<input type="hidden" name="wpRemember" value="1" />
<div class="form-group">
<input type="submit" name="wpLoginAttempt" class="btn btn-primary" value="<?php
echo wfMessage('settlein-skin-modal-login-login-button')->plain();
?>
"/>
<a href="<?php
echo SpecialPage::getSafeTitleFor('Userlogin')->getFullURL('type=signup');
?>
" class="btn btn-cyanide">
<?php
echo wfMessage('settlein-skin-modal-login-signup-button')->plain();
?>
</a>
<a href="<?php
echo SpecialPage::getSafeTitleFor('PasswordReset')->getFullURL();
?>
" class="pull-right">
<?php
echo wfMessage('settlein-skin-modal-login-reset-password')->plain();
?>
</a>
</div>
</form>
</div>
<!-- Add new article popup form & wrapper -->
<div id="add-new-article-popup-wrapper">
</div>
<div class="add-new-article-popup-form">
<h3>
<?php
echo wfMessage('settlein-skin-add-new-article-window-title')->plain();
?>
</h3>
<p>
//.........这里部分代码省略.........
示例10: setCreateaccountToken
/**
* Randomly generate a new createaccount token and attach it to the current session
*/
public static function setCreateaccountToken()
{
global $wgRequest;
$wgRequest->setSessionData('wsCreateaccountToken', MWCryptRand::generateHex(32));
}
示例11: newUUIDv4
/**
* Return an RFC4122 compliant v4 UUID
*
* @param $flags integer Bitfield (supports UIDGenerator::QUICK_RAND)
* @return string
* @throws MWException
*/
public static function newUUIDv4( $flags = 0 ) {
$hex = ( $flags & self::QUICK_RAND )
? wfRandomString( 31 )
: MWCryptRand::generateHex( 31 );
return sprintf( '%s-%s-%s-%s-%s',
// "time_low" (32 bits)
substr( $hex, 0, 8 ),
// "time_mid" (16 bits)
substr( $hex, 8, 4 ),
// "time_hi_and_version" (16 bits)
'4' . substr( $hex, 12, 3 ),
// "clk_seq_hi_res (8 bits, variant is binary 10x) and "clk_seq_low" (8 bits)
dechex( 0x8 | ( hexdec( $hex[15] ) & 0x3 ) ) . $hex[16] . substr( $hex, 17, 2 ),
// "node" (48 bits)
substr( $hex, 19, 12 )
);
}
示例12: renewSessionId
/**
* Renew the user's session id, using strong entropy
*/
private function renewSessionId()
{
global $wgSecureLogin, $wgCookieSecure;
if ($wgSecureLogin && !$this->mStickHTTPS) {
$wgCookieSecure = false;
}
// If either we don't trust PHP's entropy, or if we need
// to change cookie settings when logging in because of
// wpStickHTTPS, then change the session ID manually.
$cookieParams = session_get_cookie_params();
if (wfCheckEntropy() && $wgCookieSecure == $cookieParams['secure']) {
session_regenerate_id(false);
} else {
$tmp = $_SESSION;
session_destroy();
wfSetupSession(MWCryptRand::generateHex(32));
$_SESSION = $tmp;
}
}
示例13: execute
/**
* Execute
* @param $par Parameter passed to the page
*/
function execute($par)
{
global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker;
$user = $this->getUser();
$output = $this->getOutput();
# Anons don't get a watchlist
if ($user->isAnon()) {
$output->setPageTitle($this->msg('watchnologin'));
$output->setRobotPolicy('noindex,nofollow');
$llink = Linker::linkKnown(SpecialPage::getTitleFor('Userlogin'), $this->msg('loginreqlink')->escaped(), array(), array('returnto' => $this->getTitle()->getPrefixedText()));
$output->addHTML($this->msg('watchlistanontext')->rawParams($llink)->parse());
return;
}
// Add feed links
$wlToken = $user->getOption('watchlisttoken');
if (!$wlToken) {
$wlToken = MWCryptRand::generateHex(40);
$user->setOption('watchlisttoken', $wlToken);
$user->saveSettings();
}
$this->addFeedLinks(array('action' => 'feedwatchlist', 'allrev' => 'allrev', 'wlowner' => $user->getName(), 'wltoken' => $wlToken));
$this->setHeaders();
$this->outputHeader();
$output->addSubtitle($this->msg('watchlistfor2', $user->getName())->rawParams(SpecialEditWatchlist::buildTools(null)));
$request = $this->getRequest();
$mode = SpecialEditWatchlist::getMode($request, $par);
if ($mode !== false) {
# TODO: localise?
switch ($mode) {
case SpecialEditWatchlist::EDIT_CLEAR:
$mode = 'clear';
break;
case SpecialEditWatchlist::EDIT_RAW:
$mode = 'raw';
break;
default:
$mode = null;
}
$title = SpecialPage::getTitleFor('EditWatchlist', $mode);
$output->redirect($title->getLocalUrl());
return;
}
$nitems = $this->countItems();
if ($nitems == 0) {
$output->addWikiMsg('nowatchlist');
return;
}
// @TODO: use FormOptions!
$defaults = array('days' => floatval($user->getOption('watchlistdays')), 'hideMinor' => (int) $user->getBoolOption('watchlisthideminor'), 'hideBots' => (int) $user->getBoolOption('watchlisthidebots'), 'hideAnons' => (int) $user->getBoolOption('watchlisthideanons'), 'hideLiu' => (int) $user->getBoolOption('watchlisthideliu'), 'hidePatrolled' => (int) $user->getBoolOption('watchlisthidepatrolled'), 'hideOwn' => (int) $user->getBoolOption('watchlisthideown'), 'namespace' => 'all', 'invert' => false, 'associated' => false);
$this->customFilters = array();
wfRunHooks('SpecialWatchlistFilters', array($this, &$this->customFilters));
foreach ($this->customFilters as $key => $params) {
$defaults[$key] = $params['msg'];
}
# Extract variables from the request, falling back to user preferences or
# other default values if these don't exist
$prefs['days'] = floatval($user->getOption('watchlistdays'));
$prefs['hideminor'] = $user->getBoolOption('watchlisthideminor');
$prefs['hidebots'] = $user->getBoolOption('watchlisthidebots');
$prefs['hideanons'] = $user->getBoolOption('watchlisthideanons');
$prefs['hideliu'] = $user->getBoolOption('watchlisthideliu');
$prefs['hideown'] = $user->getBoolOption('watchlisthideown');
$prefs['hidepatrolled'] = $user->getBoolOption('watchlisthidepatrolled');
# Get query variables
$values = array();
$values['days'] = $request->getVal('days', $prefs['days']);
$values['hideMinor'] = (int) $request->getBool('hideMinor', $prefs['hideminor']);
$values['hideBots'] = (int) $request->getBool('hideBots', $prefs['hidebots']);
$values['hideAnons'] = (int) $request->getBool('hideAnons', $prefs['hideanons']);
$values['hideLiu'] = (int) $request->getBool('hideLiu', $prefs['hideliu']);
$values['hideOwn'] = (int) $request->getBool('hideOwn', $prefs['hideown']);
$values['hidePatrolled'] = (int) $request->getBool('hidePatrolled', $prefs['hidepatrolled']);
foreach ($this->customFilters as $key => $params) {
$values[$key] = (int) $request->getBool($key);
}
# Get namespace value, if supplied, and prepare a WHERE fragment
$nameSpace = $request->getIntOrNull('namespace');
$invert = $request->getBool('invert');
$associated = $request->getBool('associated');
if (!is_null($nameSpace)) {
$eq_op = $invert ? '!=' : '=';
$bool_op = $invert ? 'AND' : 'OR';
$nameSpace = intval($nameSpace);
// paranioa
if (!$associated) {
$nameSpaceClause = "rc_namespace {$eq_op} {$nameSpace}";
} else {
$associatedNS = MWNamespace::getAssociated($nameSpace);
$nameSpaceClause = "rc_namespace {$eq_op} {$nameSpace} " . $bool_op . " rc_namespace {$eq_op} {$associatedNS}";
}
} else {
$nameSpace = '';
$nameSpaceClause = '';
}
$values['namespace'] = $nameSpace;
$values['invert'] = $invert;
//.........这里部分代码省略.........
示例14: renewSessionId
/**
* Renew the user's session id, using strong entropy
*/
private function renewSessionId()
{
if (wfCheckEntropy()) {
session_regenerate_id(false);
} else {
//If we don't trust PHP's entropy, we have to replace the session manually
$tmp = $_SESSION;
session_unset();
session_write_close();
session_id(MWCryptRand::generateHex(32));
session_start();
$_SESSION = $tmp;
}
}
示例15: scratchTitle
/**
* @return Title
*/
function scratchTitle()
{
return Title::makeTitle(NS_LQT_THREAD, MWCryptRand::generateHex(32));
}