aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/config/passwords.yml8
-rw-r--r--phpBB/phpbb/passwords/driver/base.php8
-rw-r--r--phpBB/phpbb/passwords/driver/driver_interface.php7
-rw-r--r--phpBB/phpbb/passwords/driver/sha1_smf.php58
-rw-r--r--tests/passwords/drivers_test.php33
-rw-r--r--tests/passwords/manager_test.php1
6 files changed, 115 insertions, 0 deletions
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
@@ -23,6 +23,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
*
* @return string 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 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2014 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+namespace phpbb\passwords\driver;
+
+/**
+* @package passwords
+*/
+class sha1_smf extends base
+{
+ const PREFIX = '$smf$';
+
+ /**
+ * @inheritdoc
+ */
+ public function get_prefix()
+ {
+ return self::PREFIX;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function is_legacy()
+ {
+ return true;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function hash($password, $user_row = '')
+ {
+ return (isset($user_row['login_name'])) ? sha1(strtolower($user_row['login_name']) . $password) : false;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function check($password, $hash, $user_row = array())
+ {
+ return $hash === $this->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;