1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-05 23:25:30 +02:00

[feature/passwords] Add driver helper class for additional functions

Functions for the helper class might be used in other drivers as well and
therefore shouldn't be limited to just one driver.

PHPBB3-11610
This commit is contained in:
Marc Alexander 2013-06-15 13:34:05 +02:00
parent c9fafcefd3
commit 61e98fbd63
3 changed files with 9 additions and 28 deletions

View File

@ -23,6 +23,9 @@ abstract class phpbb_crypto_driver_base implements phpbb_crypto_driver_interface
/** @var phpbb_config */
protected $config;
/** @var phpbb_crypto_driver_helper */
protected $helper;
/**
* Constructor of crypto driver object
*
@ -31,6 +34,7 @@ abstract class phpbb_crypto_driver_base implements phpbb_crypto_driver_interface
public function __construct(phpbb_config $config)
{
$this->config = $config;
$this->helper = new phpbb_crypto_driver_helper($this);
}
/**

View File

@ -68,7 +68,7 @@ class phpbb_crypto_driver_salted_md5 extends phpbb_crypto_driver_base
while (--$settings['count']);
$output = $settings['full'];
$output .= _hash_encode64($hash, 16, $this->itoa);
$output .= $this->helper->hash_encode64($hash, 16, $this->itoa);
if (strlen($output) == 34)
{
@ -97,28 +97,6 @@ class phpbb_crypto_driver_salted_md5 extends phpbb_crypto_driver_base
return false;
}
/**
* Return unique id
* @param string $extra additional entropy
*/
protected function unique_id($extra = 'c')
{
static $dss_seeded = false;
$val = $this->config['rand_seed'] . microtime();
$val = md5($val);
$this->config['rand_seed'] = md5($this->config['rand_seed'] . $val . $extra);
if ($dss_seeded !== true && ($this->config['rand_seed_last_update'] < time() - rand(1,10)))
{
set_config('rand_seed_last_update', time(), true);
set_config('rand_seed', $this->config['rand_seed'], true);
$dss_seeded = true;
}
return substr($val, 4, 16);
}
/**
* Generate salt for hashing method
*
@ -139,11 +117,11 @@ class phpbb_crypto_driver_salted_md5 extends phpbb_crypto_driver_base
if (strlen($random) < $count)
{
$random = '';
$random_state = unique_id();
$random_state = $this->helper->unique_id();
for ($i = 0; $i < $count; $i += 16)
{
$random_state = md5(unique_id() . $random_state);
$random_state = md5($this->helper->unique_id() . $random_state);
$random .= pack('H*', md5($random_state));
}
$random = substr($random, 0, $count);
@ -151,8 +129,7 @@ class phpbb_crypto_driver_salted_md5 extends phpbb_crypto_driver_base
$salt = '$H$';
$salt .= $this->itoa[min($count + 5, 30)];
$salt .= _hash_encode64($random, 6, $this->itoa);
var_dump($salt);
$salt .= $this->helper->hash_encode64($random, 6, $this->itoa);
return $salt;
}

View File

@ -48,7 +48,7 @@ class phpbb_crypto_manager_test extends PHPUnit_Framework_TestCase
array('', '2y', 60),
array('crypto.driver.bcrypt_2y', '2y', 60),
array('crypto.driver.bcrypt', '2a', 60),
//array('crypto.driver.salted_md5', '$H$', 45),
array('crypto.driver.salted_md5', 'H', 34),
);
}