mirror of
https://github.com/phpbb/phpbb.git
synced 2025-01-18 14:48:28 +01:00
[feature/passwords] Pass list of default types to passwords manager
This list is in the order of how the driver types would be used. If a driver is not supported we will try the subsequent one. PHPBB3-11610
This commit is contained in:
parent
760f148a2b
commit
5193b3279c
@ -1,5 +1,9 @@
|
|||||||
parameters:
|
parameters:
|
||||||
passwords.algorithm: passwords.driver.bcrypt_2y
|
passwords.algorithms:
|
||||||
|
- passwords.driver.bcrypt_2y
|
||||||
|
- passwords.driver.bcrypt
|
||||||
|
- passwords.driver.salted_md5
|
||||||
|
- passwords.driver.phpass
|
||||||
|
|
||||||
services:
|
services:
|
||||||
passwords.driver.bcrypt:
|
passwords.driver.bcrypt:
|
||||||
@ -60,7 +64,7 @@ services:
|
|||||||
- @config
|
- @config
|
||||||
- @passwords.driver_collection
|
- @passwords.driver_collection
|
||||||
- @passwords.helper
|
- @passwords.helper
|
||||||
- %passwords.algorithm%
|
- %passwords.algorithms%
|
||||||
|
|
||||||
passwords.helper:
|
passwords.helper:
|
||||||
class: phpbb\passwords\helper
|
class: phpbb\passwords\helper
|
||||||
|
@ -63,15 +63,34 @@ class manager
|
|||||||
* @param array $hashing_algorithms Hashing driver
|
* @param array $hashing_algorithms Hashing driver
|
||||||
* service collection
|
* service collection
|
||||||
* @param phpbb\passwords\helper $helper Passwords helper object
|
* @param phpbb\passwords\helper $helper Passwords helper object
|
||||||
* @param string $default Default driver name
|
* @param string $defaults List of default driver types
|
||||||
*/
|
*/
|
||||||
public function __construct(\phpbb\config\config $config, $hashing_algorithms, \phpbb\passwords\helper $helper, $default)
|
public function __construct(\phpbb\config\config $config, $hashing_algorithms, \phpbb\passwords\helper $helper, $defaults)
|
||||||
{
|
{
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->type = $default;
|
|
||||||
|
|
||||||
$this->fill_type_map($hashing_algorithms);
|
$this->fill_type_map($hashing_algorithms);
|
||||||
$this->load_passwords_helper($helper);
|
$this->load_passwords_helper($helper);
|
||||||
|
$this->register_default_type($defaults);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register default type
|
||||||
|
* Will register the first supported type from the list of default types
|
||||||
|
*
|
||||||
|
* @param array $defaults List of default types in order from first to
|
||||||
|
* use to last to use
|
||||||
|
*/
|
||||||
|
protected function register_default_type($defaults)
|
||||||
|
{
|
||||||
|
foreach ($defaults as $type)
|
||||||
|
{
|
||||||
|
if ($this->algorithms[$type]->is_supported())
|
||||||
|
{
|
||||||
|
$this->type = $type;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,8 +27,8 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case
|
|||||||
$this->user = $this->getMock('\phpbb\user');
|
$this->user = $this->getMock('\phpbb\user');
|
||||||
$driver_helper = new \phpbb\passwords\driver\helper($config);
|
$driver_helper = new \phpbb\passwords\driver\helper($config);
|
||||||
$passwords_drivers = array(
|
$passwords_drivers = array(
|
||||||
'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $driver_helper),
|
|
||||||
'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper),
|
'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper),
|
||||||
|
'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $driver_helper),
|
||||||
'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $driver_helper),
|
'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $driver_helper),
|
||||||
'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $driver_helper),
|
'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $driver_helper),
|
||||||
);
|
);
|
||||||
@ -40,7 +40,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case
|
|||||||
|
|
||||||
$passwords_helper = new \phpbb\passwords\helper;
|
$passwords_helper = new \phpbb\passwords\helper;
|
||||||
// Set up passwords manager
|
// Set up passwords manager
|
||||||
$passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, 'passwords.driver.bcrypt_2y');
|
$passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers));
|
||||||
|
|
||||||
if (version_compare(PHP_VERSION, '5.3.7', '<'))
|
if (version_compare(PHP_VERSION, '5.3.7', '<'))
|
||||||
{
|
{
|
||||||
|
@ -37,8 +37,8 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case
|
|||||||
$user = $this->getMock('\phpbb\user');
|
$user = $this->getMock('\phpbb\user');
|
||||||
$driver_helper = new \phpbb\passwords\driver\helper($config);
|
$driver_helper = new \phpbb\passwords\driver\helper($config);
|
||||||
$passwords_drivers = array(
|
$passwords_drivers = array(
|
||||||
'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $driver_helper),
|
|
||||||
'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper),
|
'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper),
|
||||||
|
'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $driver_helper),
|
||||||
'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $driver_helper),
|
'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $driver_helper),
|
||||||
'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $driver_helper),
|
'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $driver_helper),
|
||||||
);
|
);
|
||||||
@ -50,7 +50,7 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case
|
|||||||
|
|
||||||
$passwords_helper = new \phpbb\passwords\helper;
|
$passwords_helper = new \phpbb\passwords\helper;
|
||||||
// Set up passwords manager
|
// Set up passwords manager
|
||||||
$passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, 'passwords.driver.bcrypt_2y');
|
$passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers));
|
||||||
|
|
||||||
$provider = new \phpbb\auth\provider\db($db, $config, $passwords_manager, $request, $user, $phpbb_root_path, $phpEx);
|
$provider = new \phpbb\auth\provider\db($db, $config, $passwords_manager, $request, $user, $phpbb_root_path, $phpEx);
|
||||||
if (version_compare(PHP_VERSION, '5.3.7', '<'))
|
if (version_compare(PHP_VERSION, '5.3.7', '<'))
|
||||||
|
@ -16,8 +16,8 @@ class phpbb_passwords_helper_test extends PHPUnit_Framework_TestCase
|
|||||||
$this->driver_helper = new \phpbb\passwords\driver\helper($config);
|
$this->driver_helper = new \phpbb\passwords\driver\helper($config);
|
||||||
|
|
||||||
$this->passwords_drivers = array(
|
$this->passwords_drivers = array(
|
||||||
'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $this->driver_helper),
|
|
||||||
'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $this->driver_helper),
|
'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $this->driver_helper),
|
||||||
|
'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $this->driver_helper),
|
||||||
'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $this->driver_helper),
|
'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $this->driver_helper),
|
||||||
'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $this->driver_helper),
|
'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $this->driver_helper),
|
||||||
);
|
);
|
||||||
|
@ -22,8 +22,8 @@ class phpbb_passwords_manager_test extends PHPUnit_Framework_TestCase
|
|||||||
$this->driver_helper = new \phpbb\passwords\driver\helper($config);
|
$this->driver_helper = new \phpbb\passwords\driver\helper($config);
|
||||||
|
|
||||||
$this->passwords_drivers = array(
|
$this->passwords_drivers = array(
|
||||||
'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $this->driver_helper),
|
|
||||||
'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $this->driver_helper),
|
'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $this->driver_helper),
|
||||||
|
'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $this->driver_helper),
|
||||||
'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $this->driver_helper),
|
'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $this->driver_helper),
|
||||||
'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $this->driver_helper),
|
'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $this->driver_helper),
|
||||||
);
|
);
|
||||||
@ -35,7 +35,7 @@ class phpbb_passwords_manager_test extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->helper = new \phpbb\passwords\helper;
|
$this->helper = new \phpbb\passwords\helper;
|
||||||
// Set up passwords manager
|
// Set up passwords manager
|
||||||
$this->manager = new \phpbb\passwords\manager($config, $this->passwords_drivers, $this->helper, 'passwords.driver.bcrypt_2y');
|
$this->manager = new \phpbb\passwords\manager($config, $this->passwords_drivers, $this->helper, array_keys($this->passwords_drivers));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hash_password_data()
|
public function hash_password_data()
|
||||||
|
@ -19,8 +19,8 @@ class phpbb_security_hash_test extends phpbb_test_case
|
|||||||
$phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
|
$phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
|
||||||
$driver_helper = new \phpbb\passwords\driver\helper($config);
|
$driver_helper = new \phpbb\passwords\driver\helper($config);
|
||||||
$passwords_drivers = array(
|
$passwords_drivers = array(
|
||||||
'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $driver_helper),
|
|
||||||
'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper),
|
'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper),
|
||||||
|
'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $driver_helper),
|
||||||
'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $driver_helper),
|
'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $driver_helper),
|
||||||
'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $driver_helper),
|
'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $driver_helper),
|
||||||
);
|
);
|
||||||
@ -32,7 +32,7 @@ class phpbb_security_hash_test extends phpbb_test_case
|
|||||||
|
|
||||||
$passwords_helper = new \phpbb\passwords\helper;
|
$passwords_helper = new \phpbb\passwords\helper;
|
||||||
// Set up passwords manager
|
// Set up passwords manager
|
||||||
$passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, 'passwords.driver.bcrypt_2y');
|
$passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers));
|
||||||
|
|
||||||
$phpbb_container
|
$phpbb_container
|
||||||
->expects($this->any())
|
->expects($this->any())
|
||||||
|
@ -1003,8 +1003,8 @@ class phpbb_functional_test_case extends phpbb_test_case
|
|||||||
$driver_helper = new \phpbb\passwords\driver\helper($config);
|
$driver_helper = new \phpbb\passwords\driver\helper($config);
|
||||||
|
|
||||||
$passwords_drivers = array(
|
$passwords_drivers = array(
|
||||||
'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $driver_helper),
|
|
||||||
'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper),
|
'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper),
|
||||||
|
'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $driver_helper),
|
||||||
'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $driver_helper),
|
'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $driver_helper),
|
||||||
'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $driver_helper),
|
'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $driver_helper),
|
||||||
);
|
);
|
||||||
@ -1016,7 +1016,7 @@ class phpbb_functional_test_case extends phpbb_test_case
|
|||||||
|
|
||||||
$passwords_helper = new \phpbb\passwords\helper;
|
$passwords_helper = new \phpbb\passwords\helper;
|
||||||
// Set up passwords manager
|
// Set up passwords manager
|
||||||
$manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, 'passwords.driver.bcrypt_2y');
|
$manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers));
|
||||||
|
|
||||||
return $manager;
|
return $manager;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user