diff --git a/lib/Crypto/AbstractAlgorithm.php b/lib/Crypto/AbstractAlgorithm.php index 9556d78..09bbbe6 100644 --- a/lib/Crypto/AbstractAlgorithm.php +++ b/lib/Crypto/AbstractAlgorithm.php @@ -74,4 +74,12 @@ abstract class AbstractAlgorithm implements IPasswordAlgorithm * @inheritdoc */ public abstract function getPasswordHash($password); + + /** + * @inheritdoc + */ + public function configuration() + { + return []; + } } diff --git a/lib/Crypto/CryptArgon2.php b/lib/Crypto/CryptArgon2.php index ed4aafb..535f1e8 100644 --- a/lib/Crypto/CryptArgon2.php +++ b/lib/Crypto/CryptArgon2.php @@ -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 */ diff --git a/lib/Crypto/CryptBlowfish.php b/lib/Crypto/CryptBlowfish.php index 6e1b8a5..a3e2577 100644 --- a/lib/Crypto/CryptBlowfish.php +++ b/lib/Crypto/CryptBlowfish.php @@ -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. * diff --git a/lib/Crypto/CryptExtendedDES.php b/lib/Crypto/CryptExtendedDES.php index d6654c4..235e563 100644 --- a/lib/Crypto/CryptExtendedDES.php +++ b/lib/Crypto/CryptExtendedDES.php @@ -48,6 +48,19 @@ class CryptExtendedDES extends AbstractCrypt $this->iterationCount = $iterationCount; } + /** + * @inheritdoc + */ + public function configuration() + { + return [ + [ + "name" => "iterations", "visible_name" => "Iterations", "default" => 1000, + "min" => 0, "max" => 16777215 + ] + ]; + } + /** * @inheritdoc */ @@ -76,7 +89,7 @@ class CryptExtendedDES extends AbstractCrypt while ($number) { $rem = $number % $base; $number = (int)($number / $base); - $arr[] = $alphabet[$rem]; + $chars[] = $alphabet[$rem]; } return str_pad(implode($chars), 4, ".", STR_PAD_RIGHT); diff --git a/lib/Crypto/CryptSHA256.php b/lib/Crypto/CryptSHA256.php index b4e2b41..75515eb 100644 --- a/lib/Crypto/CryptSHA256.php +++ b/lib/Crypto/CryptSHA256.php @@ -49,6 +49,19 @@ class CryptSHA256 extends AbstractCrypt $this->rounds = $rounds; } + /** + * @inheritdoc + */ + public function configuration() + { + return [ + [ + "name" => "rounds", "visible_name" => "Rounds", "default" => 5000, + "min" => 1000, "max" => 999999999 + ] + ]; + } + /** * @inheritdoc */ diff --git a/lib/Crypto/CryptSHA512.php b/lib/Crypto/CryptSHA512.php index e32238f..b638175 100644 --- a/lib/Crypto/CryptSHA512.php +++ b/lib/Crypto/CryptSHA512.php @@ -49,6 +49,19 @@ class CryptSHA512 extends AbstractCrypt $this->rounds = $rounds; } + /** + * @inheritdoc + */ + public function configuration() + { + return [ + [ + "name" => "rounds", "visible_name" => "Rounds", "default" => 5000, + "min" => 1000, "max" => 999999999 + ] + ]; + } + /** * @inheritdoc */ diff --git a/lib/Crypto/IPasswordAlgorithm.php b/lib/Crypto/IPasswordAlgorithm.php index 47ba961..1f33356 100644 --- a/lib/Crypto/IPasswordAlgorithm.php +++ b/lib/Crypto/IPasswordAlgorithm.php @@ -56,4 +56,13 @@ interface IPasswordAlgorithm * @return boolean True if the password is correct, false otherwise. */ 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(); } diff --git a/lib/Crypto/Phpass.php b/lib/Crypto/Phpass.php index d193917..dae4eab 100644 --- a/lib/Crypto/Phpass.php +++ b/lib/Crypto/Phpass.php @@ -143,6 +143,19 @@ class Phpass extends AbstractAlgorithm return $output; } + /** + * @inheritdoc + */ + public function configuration() + { + return [ + [ + "name" => "iterations", "visible_name" => "Iterations (log2)", + "default" => 8, "min" => 4, "max" => 31 + ] + ]; + } + /** * @inheritdoc */ diff --git a/tests/Crypto/CryptExtendedDESTest.php b/tests/Crypto/CryptExtendedDESTest.php index c5627e0..5f820b6 100644 --- a/tests/Crypto/CryptExtendedDESTest.php +++ b/tests/Crypto/CryptExtendedDESTest.php @@ -41,7 +41,7 @@ class CryptExtendedDESTest extends TestCase public function testCheckPassword() { $this->assertTrue( - $this->crypto->checkPassword("password", "..UZoIyj/Hy/c") + $this->crypto->checkPassword("password", "cDRpdxPmHpzS.") ); }