本文整理汇总了PHP中Random::getBytes方法的典型用法代码示例。如果您正苦于以下问题:PHP Random::getBytes方法的具体用法?PHP Random::getBytes怎么用?PHP Random::getBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Random
的用法示例。
在下文中一共展示了Random::getBytes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tryGeneratePublicToken
public static function tryGeneratePublicToken()
{
$Settings = Settings::getInstance();
if ($Settings['ApiPublic']['IntValue'] < time()) {
$PublicToken = md5(Random::getBytes(2048));
// Store old token so that running requests don't fail
if (isset($Settings['ApiPublic'])) {
$Settings['ApiPublicOld'] = array('IntValue' => $Settings['ApiPublic']['IntValue'], 'TextValue' => $Settings['ApiPublic']['TextValue']);
}
// New token
$Settings['ApiPublic'] = array('IntValue' => time() + self::$PublicUpdateInterval, 'TextValue' => $PublicToken);
}
}
示例2: generateKey40
private static function generateKey40()
{
return sha1(Random::getBytes(2048));
}
示例3: mintRand
/**
* Generate a Version 4 UUID.
* These are derived soly from random numbers.
*/
protected static function mintRand()
{
// generate random fields
$uuid = Random::getBytes(16);
// set variant
$uuid[8] = chr(ord($uuid[8]) & self::clearVar | self::varRFC);
// set version
$uuid[6] = chr(ord($uuid[6]) & self::clearVer | self::version4);
return $uuid;
}
示例4: header
<?php
header("Content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
define("LOCALE_SETUP", true);
require_once "../../lib/private/connector.class.php";
require_once "../../lib/private/random.class.php";
require_once "../../lib/config/config.php";
$Out = Out::getInstance();
$Connector = Connector::getInstance();
$TestQuery = $Connector->prepare("SELECT Login FROM `" . RP_TABLE_PREFIX . "User` WHERE UserId=1 LIMIT 1");
try {
$TestQuery->fetchFirst(true);
$Salt = md5(Random::getBytes(2048));
$HashedPassword = hash("sha256", sha1($_REQUEST["password"]) . $Salt);
if ($TestQuery->getAffectedRows() == 0) {
$NewAdmin = $Connector->prepare("INSERT INTO `" . RP_TABLE_PREFIX . "User` " . "VALUES(1, 'admin', 0, 'none', 'true', :Name, :Password, :Salt, '', FROM_UNIXTIME(:Now));");
$NewAdmin->BindValue(":Name", $_REQUEST["name"], PDO::PARAM_STR);
$NewAdmin->BindValue(":Password", $HashedPassword, PDO::PARAM_STR);
$NewAdmin->BindValue(":Salt", $Salt, PDO::PARAM_STR);
$NewAdmin->BindValue(":Now", time(), PDO::PARAM_STR);
$NewAdmin->execute(true);
} else {
$UpdateAdmin = $Connector->prepare("UPDATE `" . RP_TABLE_PREFIX . "User` SET `Login`= :Name, `Password`= :Password, `Salt`= :Salt WHERE UserId=1 LIMIT 1;");
$UpdateAdmin->BindValue(":Name", $_REQUEST["name"], PDO::PARAM_STR);
$UpdateAdmin->BindValue(":Password", $HashedPassword, PDO::PARAM_STR);
$UpdateAdmin->BindValue(":Salt", $Salt, PDO::PARAM_STR);
$UpdateAdmin->execute(true);
}
} catch (PDOException $Exception) {
$Out->pushError($Exception->getMessage());
示例5: generateKey32
public static function generateKey32()
{
return md5(Random::getBytes(2048));
}
示例6: InstallDefaultSettings
function InstallDefaultSettings($Prefix)
{
$Connector = Connector::getInstance();
// Add default values for settings table
$TestQuery = $Connector->prepare("SELECT * FROM `" . $Prefix . "Setting`");
$ExistingSettings = array();
$TestQuery->loop(function ($Row) use($ExistingSettings) {
array_push($ExistingSettings, $Row["Name"]);
});
if (!in_array("PurgeRaids", $ExistingSettings)) {
$Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('PurgeRaids', 7257600, '');");
}
if (!in_array("LockRaids", $ExistingSettings)) {
$Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('LockRaids', 3600, '');");
}
if (!in_array("RaidStartHour", $ExistingSettings)) {
$Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('RaidStartHour', 19, '');");
}
if (!in_array("RaidStartMinute", $ExistingSettings)) {
$Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('RaidStartMinute', 30, '');");
}
if (!in_array("RaidEndHour", $ExistingSettings)) {
$Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('RaidEndHour', 23, '');");
}
if (!in_array("RaidEndMinute", $ExistingSettings)) {
$Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('RaidEndMinute', 0, '');");
}
if (!in_array("RaidSize", $ExistingSettings)) {
$Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('RaidSize', 10, '');");
}
if (!in_array("RaidMode", $ExistingSettings)) {
$Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('RaidMode', 0, 'manual');");
}
if (!in_array("Site", $ExistingSettings)) {
$Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('Site', 0, '');");
}
if (!in_array("HelpPage", $ExistingSettings)) {
$Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('HelpPage', 0, '');");
}
if (!in_array("Theme", $ExistingSettings)) {
$Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('Theme', 0, 'cataclysm');");
}
if (!in_array("GameConfig", $ExistingSettings)) {
$Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('GameConfig', 0, 'wow');");
}
if (!in_array("TimeFormat", $ExistingSettings)) {
$Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('TimeFormat', 24, '');");
}
if (!in_array("StartOfWeek", $ExistingSettings)) {
$Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('StartOfWeek', 1, '');");
}
if (!in_array("PrimaryRole", $ExistingSettings)) {
$Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('PrimaryRole', 0, 'true');");
}
if (!in_array("ApiPrivate", $ExistingSettings)) {
$PrivateToken = dechex(crc32(Random::getBytes(2048))) . dechex(crc32(Random::getBytes(2048)));
$Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('ApiPrivate', 0, '" . $PrivateToken . "');");
}
if (!in_array("Version", $ExistingSettings)) {
$Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('Version', 110, '');");
} else {
$Connector->exec("UPDATE `" . $Prefix . "Setting` SET IntValue=110 WHERE Name='Version' LIMIT 1");
}
}