Skip to content

Commit 390b29a

Browse files
authored
replace rand_int to openssl_random_pseudo_bytes
since random_int method is only php 7 supported, added openssl_random_pseudo_bytes as default method.
1 parent dec1e2f commit 390b29a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

libs/csrf/csrfprotector.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,19 +344,24 @@ public static function refreshToken()
344344
*/
345345
public static function generateAuthToken()
346346
{
347+
// todo - make this a member method / configurable
348+
$randLength = 32;
349+
347350
//if config tokenLength value is 0 or some non int
348351
if (intval(self::$config['tokenLength']) == 0) {
349352
self::$config['tokenLength'] = 32; //set as default
350353
}
351354

352355
//#todo - if $length > 128 throw exception
353356

354-
if (function_exists("hash_algos") && in_array("sha512", hash_algos())) {
355-
$token = hash("sha512", random_int(0, mt_getrandmax()));
357+
if (function_exists("hash_algos")
358+
&& function_exists("openssl_random_pseudo_bytes")
359+
&& in_array("sha512", hash_algos())) {
360+
$token = hash("sha512", openssl_random_pseudo_bytes ($randLength));
356361
} else {
357362
$token = '';
358363
for ($i = 0; $i < 128; ++$i) {
359-
$r = random_int(0, 35);
364+
$r = mt_rand (0, 35);
360365
if ($r < 26) {
361366
$c = chr(ord('a') + $r);
362367
} else {

0 commit comments

Comments
 (0)