Skip to content

Commit 000fe3f

Browse files
author
Stanislav Idolov
authored
ENGCOM-944: #5463 - Use specified hashing algo in \Magento\Framework\Encryption\Encryptor::getHash #13886
2 parents 88dab2c + 9a5b077 commit 000fe3f

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

lib/internal/Magento/Framework/Encryption/Encryptor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function validateCipher($version)
143143
public function getHash($password, $salt = false, $version = self::HASH_VERSION_LATEST)
144144
{
145145
if ($salt === false) {
146-
return $this->hash($password);
146+
return $this->hash($password, $version);
147147
}
148148
if ($salt === true) {
149149
$salt = self::DEFAULT_SALT_LENGTH;
@@ -155,7 +155,7 @@ public function getHash($password, $salt = false, $version = self::HASH_VERSION_
155155
return implode(
156156
self::DELIMITER,
157157
[
158-
$this->hash($salt . $password),
158+
$this->hash($salt . $password, $version),
159159
$salt,
160160
$version
161161
]

lib/internal/Magento/Framework/Encryption/Test/Unit/EncryptorTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,32 @@ public function testValidateKey()
207207
$this->assertEquals($expectedEncryptedData, $actualEncryptedData);
208208
$this->assertEquals($crypt->decrypt($expectedEncryptedData), $actual->decrypt($actualEncryptedData));
209209
}
210+
211+
public function testUseSpecifiedHashingAlgoDataProvider()
212+
{
213+
return [
214+
['password', 'salt', Encryptor::HASH_VERSION_MD5,
215+
'67a1e09bb1f83f5007dc119c14d663aa:salt:0'],
216+
['password', 'salt', Encryptor::HASH_VERSION_SHA256,
217+
'13601bda4ea78e55a07b98866d2be6be0744e3866f13c00c811cab608a28f322:salt:1'],
218+
['password', false, Encryptor::HASH_VERSION_MD5,
219+
'5f4dcc3b5aa765d61d8327deb882cf99'],
220+
['password', false, Encryptor::HASH_VERSION_SHA256,
221+
'5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8']
222+
];
223+
}
224+
225+
/**
226+
* @dataProvider testUseSpecifiedHashingAlgoDataProvider
227+
*
228+
* @param $password
229+
* @param $salt
230+
* @param $hashAlgo
231+
* @param $expected
232+
*/
233+
public function testGetHashMustUseSpecifiedHashingAlgo($password, $salt, $hashAlgo, $expected)
234+
{
235+
$hash = $this->_model->getHash($password, $salt, $hashAlgo);
236+
$this->assertEquals($expected, $hash);
237+
}
210238
}

0 commit comments

Comments
 (0)