[feature/passwords] Rename manager methods to check() and hash()

These method names are more straightforward than the previous ones.

PHPBB3-11610
This commit is contained in:
Marc Alexander 2013-10-02 13:30:36 +02:00
parent 356f3eef07
commit afb7d2e616
2 changed files with 13 additions and 13 deletions

View file

@ -189,7 +189,7 @@ class manager
* @return string|bool Password hash of supplied password or false if * @return string|bool Password hash of supplied password or false if
* if something went wrong during hashing * if something went wrong during hashing
*/ */
public function hash_password($password, $type = '') public function hash($password, $type = '')
{ {
if (strlen($password) > 4096) if (strlen($password) > 4096)
{ {
@ -235,7 +235,7 @@ class manager
* @param string $hash Stored hash * @param string $hash Stored hash
* @return string|bool True if password is correct, false if not * @return string|bool True if password is correct, false if not
*/ */
public function check_hash($password, $hash) public function check($password, $hash)
{ {
if (strlen($password) > 4096) if (strlen($password) > 4096)
{ {

View file

@ -79,7 +79,7 @@ class phpbb_passwords_manager_test extends PHPUnit_Framework_TestCase
if (!$length) if (!$length)
{ {
$this->assertEquals(false, $hash = $this->manager->hash_password($password, $type)); $this->assertEquals(false, $hash = $this->manager->hash($password, $type));
return; return;
} }
$time = microtime(true); $time = microtime(true);
@ -87,7 +87,7 @@ class phpbb_passwords_manager_test extends PHPUnit_Framework_TestCase
// Limit each test to 1 second // Limit each test to 1 second
while ((microtime(true) - $time) < 1) while ((microtime(true) - $time) < 1)
{ {
$hash = $this->manager->hash_password($password, $type); $hash = $this->manager->hash($password, $type);
preg_match('#^\$([a-zA-Z0-9\\\]*?)\$#', $hash, $match); preg_match('#^\$([a-zA-Z0-9\\\]*?)\$#', $hash, $match);
$this->assertEquals($prefix, $match[1]); $this->assertEquals($prefix, $match[1]);
$this->assertEquals($length, strlen($hash)); $this->assertEquals($length, strlen($hash));
@ -126,10 +126,10 @@ class phpbb_passwords_manager_test extends PHPUnit_Framework_TestCase
// Limit each test to 1 second // Limit each test to 1 second
while ((microtime(true) - $time) < 1) while ((microtime(true) - $time) < 1)
{ {
$hash = $this->manager->hash_password($password, $hash_type); $hash = $this->manager->hash($password, $hash_type);
$this->assertEquals(true, $this->manager->check_hash($password, $hash)); $this->assertEquals(true, $this->manager->check($password, $hash));
$password .= $this->pw_characters[mt_rand(0, 66)]; $password .= $this->pw_characters[mt_rand(0, 66)];
$this->assertEquals(false, $this->manager->check_hash($password, $hash)); $this->assertEquals(false, $this->manager->check($password, $hash));
} }
// Check if convert_flag is correctly set // Check if convert_flag is correctly set
@ -154,7 +154,7 @@ class phpbb_passwords_manager_test extends PHPUnit_Framework_TestCase
*/ */
public function test_check_hash_exceptions($password, $hash, $expected) public function test_check_hash_exceptions($password, $hash, $expected)
{ {
$this->assertEquals($expected, $this->manager->check_hash($password, $hash)); $this->assertEquals($expected, $this->manager->check($password, $hash));
} }
public function test_hash_password_length() public function test_hash_password_length()
@ -167,7 +167,7 @@ class phpbb_passwords_manager_test extends PHPUnit_Framework_TestCase
public function test_hash_password_8bit_bcrypt() public function test_hash_password_8bit_bcrypt()
{ {
$this->assertEquals(false, $this->manager->hash_password('foobar𝄞', 'passwords.driver.bcrypt')); $this->assertEquals(false, $this->manager->hash('foobar𝄞', 'passwords.driver.bcrypt'));
} }
public function test_combined_hash_data() public function test_combined_hash_data()
@ -232,11 +232,11 @@ class phpbb_passwords_manager_test extends PHPUnit_Framework_TestCase
// Limit each test to 1 second // Limit each test to 1 second
while ((microtime(true) - $time) < 1) while ((microtime(true) - $time) < 1)
{ {
$hash = $this->manager->hash_password($password, $first_type); $hash = $this->manager->hash($password, $first_type);
$combined_hash = $this->manager->hash_password($hash, $second_type); $combined_hash = $this->manager->hash($hash, $second_type);
$this->assertEquals($expected, $this->manager->check_hash($password, $combined_hash)); $this->assertEquals($expected, $this->manager->check($password, $combined_hash));
$password .= $this->pw_characters[mt_rand(0, 66)]; $password .= $this->pw_characters[mt_rand(0, 66)];
$this->assertEquals(false, $this->manager->check_hash($password, $combined_hash)); $this->assertEquals(false, $this->manager->check($password, $combined_hash));
// If we are expecting the check to fail then there is // If we are expecting the check to fail then there is
// no need to run this more than once // no need to run this more than once