Unit tests for Crypto package

This commit is contained in:
Marcin Łojewski
2018-06-10 21:30:01 +02:00
parent 97146d6429
commit f2f3a897a5
22 changed files with 1003 additions and 7 deletions

View File

@@ -48,7 +48,7 @@ abstract class AbstractCrypt extends AbstractAlgorithm
*/
public function getPasswordHash($password)
{
return crypt($password, self::getSalt());
return crypt($password, $this->getSalt());
}
/**

View File

@@ -59,6 +59,12 @@ class CryptArgon2 extends AbstractAlgorithm
$timeCost = PASSWORD_ARGON2_DEFAULT_TIME_COST,
$threads = PASSWORD_ARGON2_DEFAULT_THREADS
) {
if (version_compare(PHP_VERSION, "7.2.0") === -1) {
throw new \RuntimeException(
"PASSWORD_ARGON2I requires PHP 7.2.0 or above."
);
}
parent::__construct($localization);
$this->memoryCost = $memoryCost;
$this->timeCost = $timeCost;

View File

@@ -45,12 +45,11 @@ class Joomla extends AbstractAlgorithm
*/
public function getPasswordHash($password)
{
return md5(
$password . ":" . Utils::randomString(
32,
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
)
$salt = Utils::randomString(
32, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
);
return md5($password . $salt) . ":" . $salt;
}
/**

View File

@@ -48,7 +48,7 @@ abstract class SSHA extends AbstractAlgorithm
$saltedPassword = base64_decode(
preg_replace("/" . $this->getPrefix() . "/i", "", $dbHash)
);
$salt = substr($saltedPassword, -(strlen($saltedPassword) - 32));
$salt = substr($saltedPassword, -32);
$hash = self::ssha($password, $salt);
return hash_equals($dbHash, $hash);