PHP version check for mcrypt_create_iv

Use `mcrypt_create_iv()` if PHP version is less than 7.1.0, otherwise use `random_bytes()` (introduced in PHP 7.1 to replace `mcrypt_create_iv()`)
This commit is contained in:
RalphORama 2017-10-24 16:27:00 -04:00 committed by GitHub
parent 67b1565ef8
commit 2097562596

View File

@ -69,7 +69,13 @@ function test_password($password, $salt, $test) {
}
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 (PHP_VERSION_ID < 701000) {
// 128 bits of entropy
return strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.');
}
// Otherwise, use random_bytes()
return strtr(base64_encode(random_bytes(16)), '+', '.');
}