1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 22:10:45 +02:00

[ticket/14733] Support increasing hashing cost factor

PHPBB3-14733
This commit is contained in:
Marc Alexander
2016-08-09 21:07:49 +02:00
parent 7bb4e88acd
commit 1d40c0f43b
7 changed files with 75 additions and 6 deletions

View File

@@ -17,6 +17,23 @@ class bcrypt extends base
{
const PREFIX = '$2a$';
/** @var int Hashing cost factor */
protected $cost_factor;
/**
* Constructor of passwords driver object
*
* @param \phpbb\config\config $config phpBB config
* @param \phpbb\passwords\driver\helper $helper Password driver helper
*/
public function __construct(\phpbb\config\config $config, helper $helper, $cost_factor)
{
parent::__construct($config, $helper);
// Don't allow cost factor to be below default setting
$this->cost_factor = max(10, $cost_factor);
}
/**
* {@inheritdoc}
*/
@@ -25,6 +42,18 @@ class bcrypt extends base
return self::PREFIX;
}
/**
* {@inheritdoc}
*/
public function needs_rehash($hash)
{
preg_match('/^' . preg_quote($this->get_prefix()) . '([0-9]+)\$/', $hash, $matches);
list(, $cost_factor) = $matches;
return empty($cost_factor) || $this->cost_factor !== intval($cost_factor);
}
/**
* {@inheritdoc}
*/
@@ -46,7 +75,7 @@ class bcrypt extends base
if ($salt == '')
{
$salt = $prefix . '10$' . $this->get_random_salt();
$salt = $prefix . $this->cost_factor . '$' . $this->get_random_salt();
}
$hash = crypt($password, $salt);