Skip to content

Commit c8f3c3e

Browse files
ENGCOM-943: #5463 - Use specified hashing algo in \Magento\Framework\Encryption\Encryptor::getHash #13885
- Merge Pull Request #13885 from k4emic/magento2:2.3-develop-5463 - Merged commits: 1. d537d56
2 parents c33674d + d537d56 commit c8f3c3e

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
@@ -148,7 +148,7 @@ public function validateCipher($version)
148148
public function getHash($password, $salt = false, $version = self::HASH_VERSION_LATEST)
149149
{
150150
if ($salt === false) {
151-
return $this->hash($password);
151+
return $this->hash($password, $version);
152152
}
153153
if ($salt === true) {
154154
$salt = self::DEFAULT_SALT_LENGTH;
@@ -160,7 +160,7 @@ public function getHash($password, $salt = false, $version = self::HASH_VERSION_
160160
return implode(
161161
self::DELIMITER,
162162
[
163-
$this->hash($salt . $password),
163+
$this->hash($salt . $password, $version),
164164
$salt,
165165
$version
166166
]

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)