Finally I do quick hack for PHP < 5.3.7

This commit is contained in:
Frederic Guillot 2013-03-20 21:04:06 -04:00
parent 17071d9062
commit 9986301d84
2 changed files with 15 additions and 9 deletions

View File

@ -2,14 +2,14 @@
// PHP 5.3 minimum
if (version_compare(PHP_VERSION, '5.3.7') < 0) {
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
die('This software require PHP 5.3.7 minimum');
die('This software require PHP 5.3.0 minimum');
}
// Short tags must be enabled for PHP < 5.4
if (version_compare(PHP_VERSION, '5.4.0') < 0) {
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
if (! ini_get('short_open_tag')) {

View File

@ -12,6 +12,15 @@ if (!defined('PASSWORD_BCRYPT')) {
define('PASSWORD_BCRYPT', 1);
define('PASSWORD_DEFAULT', PASSWORD_BCRYPT);
if (version_compare(PHP_VERSION, '5.3.7', '<')) {
define('PASSWORD_PREFIX', '$2a$');
}
else {
define('PASSWORD_PREFIX', '$2y$');
}
/**
* Hash the password using the specified algorithm
*
@ -46,7 +55,7 @@ if (!defined('PASSWORD_BCRYPT')) {
}
}
$required_salt_len = 22;
$hash_format = sprintf("$2y$%02d$", $cost);
$hash_format = sprintf("%s%02d$", PASSWORD_PREFIX, $cost);
break;
default:
trigger_error(sprintf("password_hash(): Unknown password hashing algorithm: %s", $algo), E_USER_WARNING);
@ -154,10 +163,10 @@ if (!defined('PASSWORD_BCRYPT')) {
'algoName' => 'unknown',
'options' => array(),
);
if (substr($hash, 0, 4) == '$2y$' && strlen($hash) == 60) {
if (substr($hash, 0, 4) == PASSWORD_PREFIX && strlen($hash) == 60) {
$return['algo'] = PASSWORD_BCRYPT;
$return['algoName'] = 'bcrypt';
list($cost) = sscanf($hash, "$2y$%d$");
list($cost) = sscanf($hash, PASSWORD_PREFIX."%d$");
$return['options']['cost'] = $cost;
}
return $return;
@ -216,6 +225,3 @@ if (!defined('PASSWORD_BCRYPT')) {
return $status === 0;
}
}