mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 21:58:52 +00:00
[ticket/12352] Add legacy passwords driver for sha1 smf type passwords
PHPBB3-12352
This commit is contained in:
parent
48679eeff8
commit
2ea45a06e7
6 changed files with 115 additions and 0 deletions
|
@ -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:
|
||||
|
|
|
@ -43,4 +43,12 @@ abstract class base implements driver_interface
|
|||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function is_legacy()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
58
phpBB/phpbb/passwords/driver/sha1_smf.php
Normal file
58
phpBB/phpbb/passwords/driver/sha1_smf.php
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue