From db6b5e0d2f14d4685b4f99f64b13d7d64a4c3577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20=C5=81ojewski?= Date: Wed, 13 Jun 2018 12:47:56 +0200 Subject: [PATCH] Fix SSHA hash --- lib/Crypto/SSHA.php | 9 ++++++++- lib/Crypto/SSHA256.php | 8 ++++++++ lib/Crypto/SSHA512.php | 8 ++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/Crypto/SSHA.php b/lib/Crypto/SSHA.php index 8e3642e..f0f46d9 100644 --- a/lib/Crypto/SSHA.php +++ b/lib/Crypto/SSHA.php @@ -48,7 +48,7 @@ abstract class SSHA extends AbstractAlgorithm $saltedPassword = base64_decode( preg_replace("/" . $this->getPrefix() . "/i", "", $dbHash) ); - $salt = substr($saltedPassword, -32); + $salt = substr($saltedPassword, -(strlen($saltedPassword) - $this->getHashLength())); $hash = self::ssha($password, $salt); return hash_equals($dbHash, $hash); @@ -84,6 +84,13 @@ abstract class SSHA extends AbstractAlgorithm */ public abstract function getAlgorithm(); + /** + * Get hash length. + * + * @return int The hash length. + */ + public abstract function getHashLength(); + /** * @inheritdoc */ diff --git a/lib/Crypto/SSHA256.php b/lib/Crypto/SSHA256.php index a1c9d38..a01cdf9 100644 --- a/lib/Crypto/SSHA256.php +++ b/lib/Crypto/SSHA256.php @@ -56,6 +56,14 @@ class SSHA256 extends SSHA return "sha256"; } + /** + * @inheritdoc + */ + public function getHashLength() + { + return 32; + } + /** * @inheritdoc */ diff --git a/lib/Crypto/SSHA512.php b/lib/Crypto/SSHA512.php index b2e15d8..78e66a1 100644 --- a/lib/Crypto/SSHA512.php +++ b/lib/Crypto/SSHA512.php @@ -56,6 +56,14 @@ class SSHA512 extends SSHA return "sha512"; } + /** + * @inheritdoc + */ + public function getHashLength() + { + return 64; + } + /** * @inheritdoc */