From 2ea45a06e724dfe9c3248fbb659d86558b55265e Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 24 Apr 2014 21:00:33 +0200 Subject: [PATCH] [ticket/12352] Add legacy passwords driver for sha1 smf type passwords PHPBB3-12352 --- phpBB/config/passwords.yml | 8 +++ phpBB/phpbb/passwords/driver/base.php | 8 +++ .../passwords/driver/driver_interface.php | 7 +++ phpBB/phpbb/passwords/driver/sha1_smf.php | 58 +++++++++++++++++++ tests/passwords/drivers_test.php | 33 +++++++++++ tests/passwords/manager_test.php | 1 + 6 files changed, 115 insertions(+) create mode 100644 phpBB/phpbb/passwords/driver/sha1_smf.php diff --git a/phpBB/config/passwords.yml b/phpBB/config/passwords.yml index 9e249a2c12..29986a85f2 100644 --- a/phpBB/config/passwords.yml +++ b/phpBB/config/passwords.yml @@ -38,6 +38,14 @@ services: tags: - { name: passwords.driver } + passwords.driver.sha1_smf: + class: phpbb\passwords\driver\sha1_smf + arguments: + - @config + - @passwords.driver_helper + tags: + - { name: passwords.driver } + passwords.driver_collection: class: phpbb\di\service_collection arguments: diff --git a/phpBB/phpbb/passwords/driver/base.php b/phpBB/phpbb/passwords/driver/base.php index fffc9d1461..b74c2d3d72 100644 --- a/phpBB/phpbb/passwords/driver/base.php +++ b/phpBB/phpbb/passwords/driver/base.php @@ -43,4 +43,12 @@ abstract class base implements driver_interface { return true; } + + /** + * @inheritdoc + */ + public function is_legacy() + { + return false; + } } diff --git a/phpBB/phpbb/passwords/driver/driver_interface.php b/phpBB/phpbb/passwords/driver/driver_interface.php index 54c9d6500e..d38681b75f 100644 --- a/phpBB/phpbb/passwords/driver/driver_interface.php +++ b/phpBB/phpbb/passwords/driver/driver_interface.php @@ -22,6 +22,13 @@ interface driver_interface */ public function is_supported(); + /** + * Check if hash type is a legacy hash type + * + * @return bool True if it's a legacy hash type, false if not + */ + public function is_legacy(); + /** * Returns the hash prefix * diff --git a/phpBB/phpbb/passwords/driver/sha1_smf.php b/phpBB/phpbb/passwords/driver/sha1_smf.php new file mode 100644 index 0000000000..f7f5587485 --- /dev/null +++ b/phpBB/phpbb/passwords/driver/sha1_smf.php @@ -0,0 +1,58 @@ +hash($password, $user_row); + } + + /** + * @inheritdoc + */ + public function get_settings_only($hash, $full = false) + { + return false; + } +} diff --git a/tests/passwords/drivers_test.php b/tests/passwords/drivers_test.php index c2104b0858..5e2518cdea 100644 --- a/tests/passwords/drivers_test.php +++ b/tests/passwords/drivers_test.php @@ -24,6 +24,7 @@ class phpbb_passwords_helper_test extends \phpbb_test_case '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.phpass' => new \phpbb\passwords\driver\phpass($config, $this->driver_helper), + 'passwords.driver.sha1_smf' => new \phpbb\passwords\driver\sha1_smf($config, $this->driver_helper), ); } @@ -82,4 +83,36 @@ class phpbb_passwords_helper_test extends \phpbb_test_case ); $this->assertEquals(false, $this->passwords_drivers['passwords.driver.salted_md5']->get_hash_settings(false)); } + + public function data_hash_sha1_smf() + { + return array( + array(false, 'test', array()), + array(false, 'test', ''), + array('6f9e2a1899e1f15708fd2e554103480eb53e8b57', 'foobar', array('login_name' => 'test')), + ); + } + + /** + * @dataProvider data_hash_sha1_smf + */ + public function test_hash_sha1_smf($expected, $password, $user_row) + { + $this->assertSame($expected, $this->passwords_drivers['passwords.driver.sha1_smf']->hash($password, $user_row)); + } + + public function data_get_settings() + { + return array( + array(false, '6f9e2a1899e1f15708fd2e554103480eb53e8b57', 'passwords.driver.sha1_smf'), + ); + } + + /** + * @dataProvider data_get_settings + */ + public function test_get_settings_only($expected, $hash, $driver) + { + $this->assertSame($expected, $this->passwords_drivers[$driver]->get_settings_only($hash)); + } } diff --git a/tests/passwords/manager_test.php b/tests/passwords/manager_test.php index f9244d59f2..83ae233e3c 100644 --- a/tests/passwords/manager_test.php +++ b/tests/passwords/manager_test.php @@ -30,6 +30,7 @@ class phpbb_passwords_manager_test extends \phpbb_test_case '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.phpass' => new \phpbb\passwords\driver\phpass($config, $this->driver_helper), + 'passwords.driver.sha1_smf' => new \phpbb\passwords\driver\sha1_smf($config, $this->driver_helper), ); $this->helper = new \phpbb\passwords\helper;