mirror of
https://github.com/friendica/friendica
synced 2025-04-26 11:50:11 +00:00
Move random Digits to Crypto class
This commit is contained in:
parent
0472c7b57d
commit
6e10bdf361
8 changed files with 167 additions and 17 deletions
|
@ -265,7 +265,6 @@ class System extends BaseObject
|
|||
function notice($s)
|
||||
function info($s)
|
||||
function is_site_admin()
|
||||
function random_digits($digits)
|
||||
function get_server()
|
||||
function get_temppath()
|
||||
function get_cachefile($file, $writemode = true)
|
||||
|
|
|
@ -18,6 +18,7 @@ use Friendica\Database\DBA;
|
|||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Term;
|
||||
use Friendica\Util\Crypto;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Proxy as ProxyUtils;
|
||||
use Friendica\Util\Temporal;
|
||||
|
@ -815,7 +816,7 @@ class Post extends BaseObject
|
|||
'$indent' => $indent,
|
||||
'$sourceapp' => L10n::t($a->sourcename),
|
||||
'$ww' => $conv->getMode() === 'network' ? $ww : '',
|
||||
'$rand_num' => random_digits(12)
|
||||
'$rand_num' => Crypto::randomDigits(12)
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -476,4 +476,30 @@ class Crypto
|
|||
|
||||
return self::decryptAES256CBC(base64url_decode($data['data']), $k, $i);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates cryptographic secure random digits
|
||||
*
|
||||
* @param string $digits The count of digits
|
||||
* @return int The random Digits
|
||||
*/
|
||||
public static function randomDigits($digits)
|
||||
{
|
||||
$rn = '';
|
||||
|
||||
if (!function_exists('random_int')) {
|
||||
// using rand() function for PHP 5.x compatibility
|
||||
for ($i = 0; $i < $digits; $i++) {
|
||||
$rn .= rand(0, 9);
|
||||
}
|
||||
} else {
|
||||
// generating cryptographically secure pseudo-random integers
|
||||
for ($i = 0; $i < $digits; $i++) {
|
||||
$rn .= random_int(0, 9);
|
||||
}
|
||||
}
|
||||
|
||||
return $rn;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue