Skip to content

Commit 8eb99e6

Browse files
committed
Handle salt in Crypto classes
1 parent 77270e6 commit 8eb99e6

21 files changed

Lines changed: 33 additions & 31 deletions

lib/Crypto/AbstractAlgorithm.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ protected abstract function getAlgorithmName();
6565
/**
6666
* @inheritdoc
6767
*/
68-
public function checkPassword($password, $dbHash)
68+
public function checkPassword($password, $dbHash, $salt = null)
6969
{
70-
return hash_equals($dbHash, $this->getPasswordHash($password));
70+
return hash_equals($dbHash, $this->getPasswordHash($password, $salt));
7171
}
7272

7373
/**
7474
* @inheritdoc
7575
*/
76-
public abstract function getPasswordHash($password);
76+
public abstract function getPasswordHash($password, $salt = null);
7777
}

lib/Crypto/AbstractCrypt.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ abstract class AbstractCrypt extends AbstractAlgorithm
3838
/**
3939
* @inheritdoc
4040
*/
41-
public function checkPassword($password, $dbHash)
41+
public function checkPassword($password, $dbHash, $salt = null)
4242
{
4343
return hash_equals($dbHash, crypt($password, $dbHash));
4444
}
4545

4646
/**
4747
* @inheritdoc
4848
*/
49-
public function getPasswordHash($password)
49+
public function getPasswordHash($password, $salt = null)
5050
{
5151
return crypt($password, $this->getSalt());
5252
}

lib/Crypto/Cleartext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(IL10N $localization)
4343
/**
4444
* @inheritdoc
4545
*/
46-
public function getPasswordHash($password)
46+
public function getPasswordHash($password, $salt = null)
4747
{
4848
return $password;
4949
}

lib/Crypto/CourierMD5.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(IL10N $localization)
4343
/**
4444
* @inheritdoc
4545
*/
46-
public function getPasswordHash($password)
46+
public function getPasswordHash($password, $salt = null)
4747
{
4848
return '{MD5}' . Utils::hexToBase64(md5($password));
4949
}

lib/Crypto/CourierMD5Raw.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(IL10N $localization)
4343
/**
4444
* @inheritdoc
4545
*/
46-
public function getPasswordHash($password)
46+
public function getPasswordHash($password, $salt = null)
4747
{
4848
return '{MD5RAW}' . md5($password);
4949
}

lib/Crypto/CourierSHA1.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(IL10N $localization)
4343
/**
4444
* @inheritdoc
4545
*/
46-
public function getPasswordHash($password)
46+
public function getPasswordHash($password, $salt = null)
4747
{
4848
return '{SHA}' . Utils::hexToBase64(sha1($password));
4949
}

lib/Crypto/CourierSHA256.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(IL10N $localization)
4343
/**
4444
* @inheritdoc
4545
*/
46-
public function getPasswordHash($password)
46+
public function getPasswordHash($password, $salt = null)
4747
{
4848
return '{SHA256}' . Utils::hexToBase64(hash('sha256', $password));
4949
}

lib/Crypto/Crypt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(IL10N $localization)
4444
/**
4545
* @inheritdoc
4646
*/
47-
public function getPasswordHash($password)
47+
public function getPasswordHash($password, $salt = null)
4848
{
4949
return password_hash($password, PASSWORD_DEFAULT);
5050
}

lib/Crypto/CryptArgon2.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ public function __construct(
8181
/**
8282
* @inheritdoc
8383
*/
84-
public function checkPassword($password, $dbHash)
84+
public function checkPassword($password, $dbHash, $salt = null)
8585
{
8686
return password_verify($password, $dbHash);
8787
}
8888

8989
/**
9090
* @inheritdoc
9191
*/
92-
public function getPasswordHash($password)
92+
public function getPasswordHash($password, $salt = null)
9393
{
9494
return password_hash(
9595
$password, PASSWORD_ARGON2I, [

lib/Crypto/CryptBlowfish.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ public function __construct(IL10N $localization, $cost = 10)
5252
/**
5353
* @inheritdoc
5454
*/
55-
public function checkPassword($password, $dbHash)
55+
public function checkPassword($password, $dbHash, $salt = null)
5656
{
5757
return password_verify($password, $dbHash);
5858
}
5959

6060
/**
6161
* @inheritdoc
6262
*/
63-
public function getPasswordHash($password)
63+
public function getPasswordHash($password, $salt = null)
6464
{
6565
return password_hash(
6666
$password, PASSWORD_BCRYPT, ["cost" => $this->cost]

0 commit comments

Comments
 (0)