diff --git a/include/api.php b/include/api.php
index 0f7fa85bd..10ee29287 100644
--- a/include/api.php
+++ b/include/api.php
@@ -43,6 +43,7 @@ use Friendica\Protocol\Diaspora;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\Proxy as ProxyUtils;
+use Friendica\Util\Strings;
use Friendica\Util\XML;
require_once 'include/conversation.php';
@@ -4802,7 +4803,7 @@ function api_friendica_remoteauth()
$dfrn_id = '0:' . $orig_id;
}
- $sec = random_string();
+ $sec = Strings::getRandomHex();
$fields = ['uid' => api_user(), 'cid' => $cid, 'dfrn_id' => $dfrn_id,
'sec' => $sec, 'expire' => time() + 45];
diff --git a/include/enotify.php b/include/enotify.php
index d6ca12327..2033027e3 100644
--- a/include/enotify.php
+++ b/include/enotify.php
@@ -15,6 +15,7 @@ use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Emailer;
+use Friendica\Util\Strings;
/**
* @brief Creates a notification entry and possibly sends a mail
@@ -457,7 +458,7 @@ function notification($params)
Logger::log("adding notification entry", Logger::DEBUG);
do {
$dups = false;
- $hash = random_string();
+ $hash = Strings::getRandomHex();
if (DBA::exists('notify', ['hash' => $hash])) {
$dups = true;
}
diff --git a/include/items.php b/include/items.php
index 9929f535f..adc5bf013 100644
--- a/include/items.php
+++ b/include/items.php
@@ -21,6 +21,7 @@ use Friendica\Protocol\OStatus;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\ParseUrl;
+use Friendica\Util\Strings;
use Friendica\Util\Temporal;
require_once 'include/text.php';
@@ -308,7 +309,7 @@ function subscribe_to_hub($url, array $importer, array $contact, $hubmode = 'sub
$push_url = System::baseUrl() . '/pubsub/' . $user['nickname'] . '/' . $contact['id'];
// Use a single verify token, even if multiple hubs
- $verify_token = ((strlen($contact['hub-verify'])) ? $contact['hub-verify'] : random_string());
+ $verify_token = ((strlen($contact['hub-verify'])) ? $contact['hub-verify'] : Strings::getRandomHex());
$params= 'hub.mode=' . $hubmode . '&hub.callback=' . urlencode($push_url) . '&hub.topic=' . urlencode($contact['poll']) . '&hub.verify=async&hub.verify_token=' . $verify_token;
diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php
index 0f001b11a..8d4594c15 100644
--- a/mod/dfrn_confirm.php
+++ b/mod/dfrn_confirm.php
@@ -33,6 +33,7 @@ use Friendica\Protocol\ActivityPub;
use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
+use Friendica\Util\Strings;
use Friendica\Util\XML;
require_once 'include/enotify.php';
@@ -263,7 +264,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
break;
case 1:
// birthday paradox - generate new dfrn-id and fall through.
- $new_dfrn_id = random_string();
+ $new_dfrn_id = Strings::getRandomHex();
q("UPDATE contact SET `issued-id` = '%s' WHERE `id` = %d AND `uid` = %d",
DBA::escape($new_dfrn_id),
intval($contact_id),
diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php
index b14c71fb8..ba2332bcb 100644
--- a/mod/dfrn_notify.php
+++ b/mod/dfrn_notify.php
@@ -14,6 +14,7 @@ use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Protocol\DFRN;
use Friendica\Protocol\Diaspora;
+use Friendica\Util\Strings;
require_once 'include/items.php';
@@ -267,7 +268,7 @@ function dfrn_notify_content(App $a) {
$dfrn_id = substr($dfrn_id,2);
}
- $hash = random_string();
+ $hash = Strings::getRandomHex();
$status = 0;
diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php
index a961506d1..9cd110917 100644
--- a/mod/dfrn_poll.php
+++ b/mod/dfrn_poll.php
@@ -14,6 +14,7 @@ use Friendica\Module\Login;
use Friendica\Protocol\DFRN;
use Friendica\Protocol\OStatus;
use Friendica\Util\Network;
+use Friendica\Util\Strings;
use Friendica\Util\XML;
require_once 'include/items.php';
@@ -415,7 +416,7 @@ function dfrn_poll_content(App $a)
if ($dfrn_id != '') {
// initial communication from external contact
- $hash = random_string();
+ $hash = Strings::getRandomHex();
$status = 0;
diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php
index fdb1a42ee..e5d5a3fe2 100644
--- a/mod/dfrn_request.php
+++ b/mod/dfrn_request.php
@@ -28,6 +28,7 @@ use Friendica\Module\Login;
use Friendica\Network\Probe;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
+use Friendica\Util\Strings;
require_once 'include/enotify.php';
@@ -320,7 +321,7 @@ function dfrn_request_post(App $a)
}
}
- $issued_id = random_string();
+ $issued_id = Strings::getRandomHex();
if (is_array($contact_record)) {
// There is a contact record but no issued-id, so this
@@ -415,7 +416,7 @@ function dfrn_request_post(App $a)
return;
}
- $hash = random_string() . (string) time(); // Generate a confirm_key
+ $hash = Strings::getRandomHex() . (string) time(); // Generate a confirm_key
if (is_array($contact_record)) {
$ret = q("INSERT INTO `intro` ( `uid`, `contact-id`, `blocked`, `knowyou`, `note`, `hash`, `datetime`)
diff --git a/mod/fsuggest.php b/mod/fsuggest.php
index 35710bb33..f87046f6c 100644
--- a/mod/fsuggest.php
+++ b/mod/fsuggest.php
@@ -9,6 +9,7 @@ use Friendica\Core\L10n;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Strings;
function fsuggest_post(App $a)
{
@@ -34,7 +35,7 @@ function fsuggest_post(App $a)
$new_contact = intval($_POST['suggest']);
- $hash = random_string();
+ $hash = Strings::getRandomHex();
$note = escape_tags(trim(defaults($_POST, 'note', '')));
diff --git a/mod/pubsubhubbub.php b/mod/pubsubhubbub.php
index ea27f0482..26a157e2f 100644
--- a/mod/pubsubhubbub.php
+++ b/mod/pubsubhubbub.php
@@ -93,7 +93,7 @@ function pubsubhubbub_init(App $a) {
}
// do subscriber verification according to the PuSH protocol
- $hub_challenge = random_string(40);
+ $hub_challenge = Strings::getRandomHex(40);
$params = 'hub.mode=' .
($subscribe == 1 ? 'subscribe' : 'unsubscribe') .
'&hub.topic=' . urlencode($hub_topic) .
diff --git a/mod/redir.php b/mod/redir.php
index 088a5f55e..6077a26f9 100644
--- a/mod/redir.php
+++ b/mod/redir.php
@@ -8,6 +8,7 @@ use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
+use Friendica\Util\Strings;
function redir_init(App $a) {
@@ -93,7 +94,7 @@ function redir_init(App $a) {
$dfrn_id = '0:' . $orig_id;
}
- $sec = random_string();
+ $sec = Strings::getRandomHex();
$fields = ['uid' => local_user(), 'cid' => $cid, 'dfrn_id' => $dfrn_id,
'sec' => $sec, 'expire' => time() + 45];
diff --git a/mod/removeme.php b/mod/removeme.php
index c2ceb7d4c..44671ef07 100644
--- a/mod/removeme.php
+++ b/mod/removeme.php
@@ -68,7 +68,7 @@ function removeme_content(App $a)
$a->internalRedirect();
}
- $hash = random_string();
+ $hash = Strings::getRandomHex();
require_once("mod/settings.php");
settings_init($a);
diff --git a/spec/dfrn2_contact_request.svg b/spec/dfrn2_contact_request.svg
index cc78be55c..34de340f3 100644
--- a/spec/dfrn2_contact_request.svg
+++ b/spec/dfrn2_contact_request.svg
@@ -38,7 +38,7 @@ text { font:12px Dialog; }
where self = 0 to look if this contact is already there (if
issued-id or rel is already available return here because it
seems that we are already connected)
-- create a issued-id with $issued_id = random_string();
+- create a issued-id with $issued_id = Strings::getRandomHex();
- if we already found a contact record above update the
issued-id with the one we have created
- otherwise if Bob is not already in the contact table scrape
diff --git a/src/Content/Text/HTML.php b/src/Content/Text/HTML.php
index cdfd41c11..9b73da56d 100644
--- a/src/Content/Text/HTML.php
+++ b/src/Content/Text/HTML.php
@@ -7,6 +7,7 @@ namespace Friendica\Content\Text;
use DOMDocument;
use DOMXPath;
+use Friendica\Content\Feature;
use Friendica\Core\Addon;
use Friendica\Core\L10n;
use Friendica\Core\Config;
@@ -17,9 +18,9 @@ use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Util\Network;
use Friendica\Util\Proxy as ProxyUtils;
+use Friendica\Util\Strings;
use Friendica\Util\XML;
use League\HTMLToMarkdown\HtmlConverter;
-use Friendica\Content\Feature;
class HTML
{
@@ -1011,7 +1012,7 @@ class HTML
$tpl = Renderer::getMarkupTemplate('wall/content_filter.tpl');
$html = Renderer::replaceMacros($tpl, [
'$reasons' => $reasons,
- '$rnd' => random_string(8),
+ '$rnd' => Strings::getRandomHex(8),
'$openclose' => L10n::t('Click to open/close'),
'$html' => $html
]);
diff --git a/src/Model/Contact.php b/src/Model/Contact.php
index 5d571e30e..1a6349d9c 100644
--- a/src/Model/Contact.php
+++ b/src/Model/Contact.php
@@ -25,6 +25,7 @@ use Friendica\Protocol\PortableContact;
use Friendica\Protocol\Salmon;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
+use Friendica\Util\Strings;
require_once 'boot.php';
require_once 'include/dba.php';
@@ -1889,7 +1890,7 @@ class Contact extends BaseObject
$user = DBA::selectFirst('user', $fields, ['uid' => $importer['uid']]);
if (DBA::isResult($user) && !in_array($user['page-flags'], [self::PAGE_SOAPBOX, self::PAGE_FREELOVE, self::PAGE_COMMUNITY])) {
// create notification
- $hash = random_string();
+ $hash = Strings::getRandomHex();
if (is_array($contact_record)) {
DBA::insert('intro', ['uid' => $importer['uid'], 'contact-id' => $contact_record['id'],
diff --git a/src/Model/Item.php b/src/Model/Item.php
index 1eb96609f..35dfb7264 100644
--- a/src/Model/Item.php
+++ b/src/Model/Item.php
@@ -33,6 +33,7 @@ use Friendica\Util\DateTimeFormat;
use Friendica\Util\Map;
use Friendica\Util\XML;
use Friendica\Util\Security;
+use Friendica\Util\Strings;
use Text_LanguageDetect;
require_once 'boot.php';
@@ -3479,7 +3480,7 @@ class Item extends BaseObject
while ((strpos($s, $spoilersearch) !== false)) {
$pos = strpos($s, $spoilersearch);
- $rnd = random_string(8);
+ $rnd = Strings::getRandomHex(8);
$spoilerreplace = '
' . L10n::t('Click to open/close') . ''.
'
';
$s = substr($s, 0, $pos) . $spoilerreplace . substr($s, $pos + strlen($spoilersearch));
@@ -3490,7 +3491,7 @@ class Item extends BaseObject
while ((strpos($s, $authorsearch) !== false)) {
$pos = strpos($s, $authorsearch);
- $rnd = random_string(8);
+ $rnd = Strings::getRandomHex(8);
$authorreplace = '
' . L10n::t('Click to open/close') . ''.
'';
$s = substr($s, 0, $pos) . $authorreplace . substr($s, $pos + strlen($authorsearch));
diff --git a/src/Model/Register.php b/src/Model/Register.php
index e54db87a6..5311c80c2 100644
--- a/src/Model/Register.php
+++ b/src/Model/Register.php
@@ -7,6 +7,7 @@ namespace Friendica\Model;
use Friendica\Database\DBA;
use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Strings;
/**
* Class interacting with the register database table
@@ -100,7 +101,7 @@ class Register
*/
public static function createForApproval($uid, $language, $note = '')
{
- $hash = random_string();
+ $hash = Strings::getRandomHex();
if (!User::exists($uid)) {
return false;
diff --git a/src/Module/Magic.php b/src/Module/Magic.php
index b8af1f961..01c5d5d46 100644
--- a/src/Module/Magic.php
+++ b/src/Module/Magic.php
@@ -11,6 +11,7 @@ use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Util\HTTPSignature;
use Friendica\Util\Network;
+use Friendica\Util\Strings;
/**
* Magic Auth (remote authentication) module.
@@ -74,7 +75,7 @@ class Magic extends BaseModule
$headers = [];
$headers['Accept'] = 'application/x-dfrn+json';
- $headers['X-Open-Web-Auth'] = random_string();
+ $headers['X-Open-Web-Auth'] = Strings::getRandomHex();
// Create a header that is signed with the local users private key.
$headers = HTTPSignature::createSig(
diff --git a/src/Module/Owa.php b/src/Module/Owa.php
index a1dbfa2f3..8832dd9b0 100644
--- a/src/Module/Owa.php
+++ b/src/Module/Owa.php
@@ -11,6 +11,7 @@ use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Model\OpenWebAuthToken;
use Friendica\Util\HTTPSignature;
+use Friendica\Util\Strings;
/**
* @brief OpenWebAuth verifier and token generator
@@ -62,7 +63,7 @@ class Owa extends BaseModule
Logger::log('OWA success: ' . $contact['addr'], Logger::DATA);
$ret['success'] = true;
- $token = random_string(32);
+ $token = Strings::getRandomHex(32);
// Store the generated token in the databe.
OpenWebAuthToken::create('owt', 0, $token, $contact['addr']);
diff --git a/src/Network/Probe.php b/src/Network/Probe.php
index fc93524bf..a9a7a93ab 100644
--- a/src/Network/Probe.php
+++ b/src/Network/Probe.php
@@ -24,6 +24,7 @@ use Friendica\Protocol\ActivityPub;
use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
+use Friendica\Util\Strings;
use Friendica\Util\XML;
use DomXPath;
@@ -1648,8 +1649,8 @@ class Probe
$data["nick"] = $data["name"];
$data["photo"] = Network::lookupAvatarByEmail($uri);
$data["url"] = 'mailto:'.$uri;
- $data["notify"] = 'smtp '.random_string();
- $data["poll"] = 'email '.random_string();
+ $data["notify"] = 'smtp ' . Strings::getRandomHex();
+ $data["poll"] = 'email ' . Strings::getRandomHex();
$x = Email::messageMeta($mbox, $msgs[0]);
if (stristr($x[0]->from, $uri)) {
diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php
index 8a2b21745..c9ad69cc1 100644
--- a/src/Protocol/DFRN.php
+++ b/src/Protocol/DFRN.php
@@ -33,6 +33,7 @@ use Friendica\Object\Image;
use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
+use Friendica\Util\Strings;
use Friendica\Util\XML;
use HTMLPurifier;
use HTMLPurifier_Config;
@@ -2009,7 +2010,7 @@ class DFRN
$fid = $r[0]["id"];
- $hash = random_string();
+ $hash = Strings::getRandomHex();
$r = q(
"INSERT INTO `intro` (`uid`, `fid`, `contact-id`, `note`, `hash`, `datetime`, `blocked`)
@@ -3030,7 +3031,7 @@ class DFRN
return;
}
- $sec = random_string();
+ $sec = Strings::getRandomHex();
DBA::insert('profile_check', ['uid' => local_user(), 'cid' => $cid, 'dfrn_id' => $dfrn_id, 'sec' => $sec, 'expire' => time() + 45]);
diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php
index 0b5c9c949..8fc17f97d 100644
--- a/src/Protocol/Diaspora.php
+++ b/src/Protocol/Diaspora.php
@@ -34,6 +34,7 @@ use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Map;
use Friendica\Util\Network;
+use Friendica\Util\Strings;
use Friendica\Util\XML;
use SimpleXMLElement;
@@ -2421,7 +2422,7 @@ class Diaspora
if (in_array($importer["page-flags"], [Contact::PAGE_NORMAL, Contact::PAGE_PRVGROUP])) {
Logger::log("Sending intra message for author ".$author.".", Logger::DEBUG);
- $hash = random_string().(string)time(); // Generate a confirm_key
+ $hash = Strings::getRandomHex().(string)time(); // Generate a confirm_key
$ret = q(
"INSERT INTO `intro` (`uid`, `contact-id`, `blocked`, `knowyou`, `note`, `hash`, `datetime`)
@@ -3055,7 +3056,7 @@ class Diaspora
return 200;
}
- $logid = random_string(4);
+ $logid = String::getRandomHex(4);
$dest_url = ($public_batch ? $contact["batch"] : $contact["notify"]);
diff --git a/src/Util/LDSignature.php b/src/Util/LDSignature.php
index e53590cf3..c9fde441f 100644
--- a/src/Util/LDSignature.php
+++ b/src/Util/LDSignature.php
@@ -54,7 +54,7 @@ class LDSignature
{
$options = [
'type' => 'RsaSignature2017',
- 'nonce' => random_string(64),
+ 'nonce' => Strings::getRandomHex(64),
'creator' => $owner['url'] . '#main-key',
'created' => DateTimeFormat::utcNow(DateTimeFormat::ATOM)
];
diff --git a/src/Util/Strings.php b/src/Util/Strings.php
index 8df9f585d..ceb1a946a 100644
--- a/src/Util/Strings.php
+++ b/src/Util/Strings.php
@@ -16,7 +16,7 @@ class Strings
* @param int $size
* @return string
*/
- public static function getRandomHex($size = 64) // random_string()
+ public static function getRandomHex($size = 64)
{
$byte_size = ceil($size / 2);