Skip to content

Commit

Permalink
Fix for deprecated mcrypt_create_iv() in PHP 7.2+
Browse files Browse the repository at this point in the history
  • Loading branch information
MioVisman committed May 20, 2018
1 parent 9f0fc20 commit 818149b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 154 deletions.
20 changes: 16 additions & 4 deletions include/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1094,10 +1094,22 @@ function forum_number_format($number, $decimals = 0)
//
function random_key($len, $readable = false, $hash = false)
{
if (!function_exists('secure_random_bytes'))
include PUN_ROOT.'include/srand.php';

$key = secure_random_bytes($len);
$key = '';
if (function_exists('random_bytes')) {
$key .= (string) random_bytes($len);
}
if (strlen($key) < $len && function_exists('mcrypt_create_iv')) {
$key .= (string) mcrypt_create_iv($len, MCRYPT_DEV_URANDOM);
}
if (strlen($key) < $len && function_exists('openssl_random_pseudo_bytes')) {
$tmp = (string) openssl_random_pseudo_bytes($len, $strong);
if ($strong) {
$key .= $tmp;
}
}
if (strlen($key) < $len) {
exit('Could not gather sufficient random data');
}

if ($hash)
return substr(bin2hex($key), 0, $len);
Expand Down
150 changes: 0 additions & 150 deletions include/srand.php

This file was deleted.

0 comments on commit 818149b

Please sign in to comment.