Skip to content

Commit db6b5e0

Browse files
committed
Fix SSHA hash
1 parent 1df4ceb commit db6b5e0

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

lib/Crypto/SSHA.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function checkPassword($password, $dbHash)
4848
$saltedPassword = base64_decode(
4949
preg_replace("/" . $this->getPrefix() . "/i", "", $dbHash)
5050
);
51-
$salt = substr($saltedPassword, -32);
51+
$salt = substr($saltedPassword, -(strlen($saltedPassword) - $this->getHashLength()));
5252
$hash = self::ssha($password, $salt);
5353

5454
return hash_equals($dbHash, $hash);
@@ -84,6 +84,13 @@ private function ssha($password, $salt)
8484
*/
8585
public abstract function getAlgorithm();
8686

87+
/**
88+
* Get hash length.
89+
*
90+
* @return int The hash length.
91+
*/
92+
public abstract function getHashLength();
93+
8794
/**
8895
* @inheritdoc
8996
*/

lib/Crypto/SSHA256.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ public function getAlgorithm()
5656
return "sha256";
5757
}
5858

59+
/**
60+
* @inheritdoc
61+
*/
62+
public function getHashLength()
63+
{
64+
return 32;
65+
}
66+
5967
/**
6068
* @inheritdoc
6169
*/

lib/Crypto/SSHA512.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ public function getAlgorithm()
5656
return "sha512";
5757
}
5858

59+
/**
60+
* @inheritdoc
61+
*/
62+
public function getHashLength()
63+
{
64+
return 64;
65+
}
66+
5967
/**
6068
* @inheritdoc
6169
*/

0 commit comments

Comments
 (0)