File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -344,19 +344,24 @@ public static function refreshToken()
344
344
*/
345
345
public static function generateAuthToken ()
346
346
{
347
+ // todo - make this a member method / configurable
348
+ $ randLength = 32 ;
349
+
347
350
//if config tokenLength value is 0 or some non int
348
351
if (intval (self ::$ config ['tokenLength ' ]) == 0 ) {
349
352
self ::$ config ['tokenLength ' ] = 32 ; //set as default
350
353
}
351
354
352
355
//#todo - if $length > 128 throw exception
353
356
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 ));
356
361
} else {
357
362
$ token = '' ;
358
363
for ($ i = 0 ; $ i < 128 ; ++$ i ) {
359
- $ r = random_int (0 , 35 );
364
+ $ r = mt_rand (0 , 35 );
360
365
if ($ r < 26 ) {
361
366
$ c = chr (ord ('a ' ) + $ r );
362
367
} else {
You can’t perform that action at this time.
0 commit comments