Hash configuration

This commit is contained in:
Marcin Łojewski
2018-07-10 22:19:50 +02:00
parent 50da49c820
commit 924886dd9a
9 changed files with 105 additions and 2 deletions

View File

@@ -74,4 +74,12 @@ abstract class AbstractAlgorithm implements IPasswordAlgorithm
* @inheritdoc * @inheritdoc
*/ */
public abstract function getPasswordHash($password); public abstract function getPasswordHash($password);
/**
* @inheritdoc
*/
public function configuration()
{
return [];
}
} }

View File

@@ -100,6 +100,27 @@ class CryptArgon2 extends AbstractAlgorithm
); );
} }
/**
* @inheritdoc
*/
public function configuration()
{
return [
[
"name" => "memoryCost", "visible_name" => "Memory cost (KiB)",
"default" => PASSWORD_ARGON2_DEFAULT_MEMORY_COST, "min" => 1, "max" => 1048576
],
[
"name" => "timeCost", "visible_name" => "Time cost",
"default" => PASSWORD_ARGON2_DEFAULT_TIME_COST, "min" => 1, "max" => 1024
],
[
"name" => "threads", "visible_name" => "Threads",
"default" => PASSWORD_ARGON2_DEFAULT_THREADS, "min" => 1, "max" => 1024
]
];
}
/** /**
* @inheritdoc * @inheritdoc
*/ */

View File

@@ -67,6 +67,19 @@ class CryptBlowfish extends AbstractAlgorithm
); );
} }
/**
* @inheritdoc
*/
public function configuration()
{
return [
[
"name" => "cost", "visible_name" => "Cost", "default" => 10,
"min" => 4, "max" => 31
]
];
}
/** /**
* Get the algorithm name. * Get the algorithm name.
* *

View File

@@ -48,6 +48,19 @@ class CryptExtendedDES extends AbstractCrypt
$this->iterationCount = $iterationCount; $this->iterationCount = $iterationCount;
} }
/**
* @inheritdoc
*/
public function configuration()
{
return [
[
"name" => "iterations", "visible_name" => "Iterations", "default" => 1000,
"min" => 0, "max" => 16777215
]
];
}
/** /**
* @inheritdoc * @inheritdoc
*/ */
@@ -76,7 +89,7 @@ class CryptExtendedDES extends AbstractCrypt
while ($number) { while ($number) {
$rem = $number % $base; $rem = $number % $base;
$number = (int)($number / $base); $number = (int)($number / $base);
$arr[] = $alphabet[$rem]; $chars[] = $alphabet[$rem];
} }
return str_pad(implode($chars), 4, ".", STR_PAD_RIGHT); return str_pad(implode($chars), 4, ".", STR_PAD_RIGHT);

View File

@@ -49,6 +49,19 @@ class CryptSHA256 extends AbstractCrypt
$this->rounds = $rounds; $this->rounds = $rounds;
} }
/**
* @inheritdoc
*/
public function configuration()
{
return [
[
"name" => "rounds", "visible_name" => "Rounds", "default" => 5000,
"min" => 1000, "max" => 999999999
]
];
}
/** /**
* @inheritdoc * @inheritdoc
*/ */

View File

@@ -49,6 +49,19 @@ class CryptSHA512 extends AbstractCrypt
$this->rounds = $rounds; $this->rounds = $rounds;
} }
/**
* @inheritdoc
*/
public function configuration()
{
return [
[
"name" => "rounds", "visible_name" => "Rounds", "default" => 5000,
"min" => 1000, "max" => 999999999
]
];
}
/** /**
* @inheritdoc * @inheritdoc
*/ */

View File

@@ -56,4 +56,13 @@ interface IPasswordAlgorithm
* @return boolean True if the password is correct, false otherwise. * @return boolean True if the password is correct, false otherwise.
*/ */
public function checkPassword($password, $dbHash); public function checkPassword($password, $dbHash);
/**
* Configuration for the algorithm.
* The return array should contain entries which define keys:
* name, visible_name, default, min, max.
*
* @return array The configuration array.
*/
public function configuration();
} }

View File

@@ -143,6 +143,19 @@ class Phpass extends AbstractAlgorithm
return $output; return $output;
} }
/**
* @inheritdoc
*/
public function configuration()
{
return [
[
"name" => "iterations", "visible_name" => "Iterations (log2)",
"default" => 8, "min" => 4, "max" => 31
]
];
}
/** /**
* @inheritdoc * @inheritdoc
*/ */

View File

@@ -41,7 +41,7 @@ class CryptExtendedDESTest extends TestCase
public function testCheckPassword() public function testCheckPassword()
{ {
$this->assertTrue( $this->assertTrue(
$this->crypto->checkPassword("password", "..UZoIyj/Hy/c") $this->crypto->checkPassword("password", "cDRpdxPmHpzS.")
); );
} }