Handle mcrypt_create_iv deprectation by using randombytes in newer PHP versions
This commit is contained in:
parent
67ef23d758
commit
7aae5ed3e9
|
@ -69,12 +69,13 @@ function test_password($password, $salt, $test) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function generate_salt() {
|
function generate_salt() {
|
||||||
// 128 bits of entropy
|
// mcrypt_create_iv() was deprecated in PHP 7.1.0, only use it if we're below that version number.
|
||||||
if (function_exists('random_bytes')) {
|
if (PHP_VERSION_ID < 70100) {
|
||||||
return strtr(base64_encode(random_bytes(16)), '+', '.');
|
// 128 bits of entropy
|
||||||
} else {
|
|
||||||
return strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.');
|
return strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.');
|
||||||
}
|
}
|
||||||
|
// Otherwise, use random_bytes()
|
||||||
|
return strtr(base64_encode(random_bytes(16)), '+', '.');
|
||||||
}
|
}
|
||||||
|
|
||||||
function login($username, $password) {
|
function login($username, $password) {
|
||||||
|
@ -210,8 +211,8 @@ function check_login($prompt = false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$mod = array(
|
$mod = array(
|
||||||
'id' => $user['id'],
|
'id' => (int)$user['id'],
|
||||||
'type' => $user['type'],
|
'type' => (int)$user['type'],
|
||||||
'username' => $cookie[0],
|
'username' => $cookie[0],
|
||||||
'boards' => explode(',', $user['boards'])
|
'boards' => explode(',', $user['boards'])
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue