Skip to content

Commit efff6a0

Browse files
committed
add php vectors
```php <?php $test = base64_encode(hash("sha256", "chipsn'dip" , true)); print(password_hash($test,PASSWORD_DEFAULT)); ``` tested using http://phptester.net/
1 parent dbd8687 commit efff6a0

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

src/BCrypt.Net.UnitTests/BCryptTests.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,18 @@ public class BCryptTests
5454
};
5555

5656
/// <summary>
57-
/// Hashes created using passlib in python prehashed using SHA256; 7 rounds on bcrypt
57+
/// Hashes created using other languages
5858
/// </summary>
59-
readonly string[,] _pythonPassLibTestVectors = {
59+
readonly string[,] _otherLibTestVectors = {
60+
//passlib in python prehashed using SHA256; 7 rounds on bcrypt
6061
{ "~!@#$%^&*() ~!@#$%^&*()PNBFRD", "$2b$07$9IpAgJw99HWJur2uj3vr3O", "$2b$07$9IpAgJw99HWJur2uj3vr3OyXMLQ05R2dQE.L5iGnbcVFgMRpsPZRG" },
6162
{ "", "$2b$07$0AD340gChkx46nsejmoRw.", "$2b$07$0AD340gChkx46nsejmoRw.ANNVeZY33cuGluoj/QhaGEFNGb3sg8O" },
6263
{ "a", "$2b$07$uCq3i6F42wcUHItGwO84jO", "$2b$07$uCq3i6F42wcUHItGwO84jObhWccJLbVf9vUyXMo0NEW8MkhQHuoS." },
6364
{ "abcdefghijklmnopqrstuvwxyz", "$2b$07$IZIyfWJFuytjdR41r/Fm7.", "$2b$07$IZIyfWJFuytjdR41r/Fm7.AeV62vhwnzULJwzXuEdtgUMADnq97fu" },
6465
{ "~!@#$%^&*() ~!@#$%^&*()PNBFRD", "$2b$07$xo54ftDxdJKeeVZcVm8y9O", "$2b$07$xo54ftDxdJKeeVZcVm8y9Ojt76V.7dAICUOYkEXHlZpzEEbuTTRpC" },
66+
// PHP password_hash
67+
{ "test", "$2y$10$u3XfEiRife.cNffWS0aD9O", "$2y$10$u3XfEiRife.cNffWS0aD9OUPdFLVsiedZcGA/fXXeRyZBlvjGyS3e" },
68+
{ "chipsn'dip", "$2y$10$9Cb83ULoFHStLMg2iKG3p.", "$2y$10$9Cb83ULoFHStLMg2iKG3p.0.ux/vJ49gZXs4FMooj44W1P8DN89Pi" },
6569
};
6670

6771
readonly char[] _revisions = new char[] { 'a', 'x', 'y', 'b' };
@@ -200,17 +204,17 @@ public void TestHashPasswordEnhanced_PASSLIB()
200204
Trace.Write("BCrypt.HashPassword(): ");
201205
var sw = Stopwatch.StartNew();
202206

203-
for (int i = 0; i < _pythonPassLibTestVectors.Length / 3; i++)
207+
for (int i = 0; i < _otherLibTestVectors.Length / 3; i++)
204208
{
205-
string plain = _pythonPassLibTestVectors[i, 0];
209+
string plain = _otherLibTestVectors[i, 0];
206210
string salt;
207211

208212
//Check hash that goes in one end comes out the next the same
209-
salt = _pythonPassLibTestVectors[i, 1];
213+
salt = _otherLibTestVectors[i, 1];
210214

211215
string hashed = BCrypt.HashPassword(plain, salt, enhancedEntropy: true, HashType.SHA256, v4CompatibleEnhancedEntropy:true);
212216

213-
Assert.Equal(hashed, _pythonPassLibTestVectors[i, 2]);
217+
Assert.Equal(hashed, _otherLibTestVectors[i, 2]);
214218

215219
var validateHashCheck = BCrypt.Verify(plain, hashed, true, HashType.SHA256, v4CompatibleEnhancedEntropy: true);
216220
Assert.True(validateHashCheck);
@@ -230,17 +234,17 @@ public void TestHashPasswordEnhanced_PASSLIB_V3EnhancedIsNotInteroperable()
230234
Trace.Write("BCrypt.HashPassword(): ");
231235
var sw = Stopwatch.StartNew();
232236

233-
for (int i = 0; i < _pythonPassLibTestVectors.Length / 3; i++)
237+
for (int i = 0; i < _otherLibTestVectors.Length / 3; i++)
234238
{
235-
string plain = _pythonPassLibTestVectors[i, 0];
239+
string plain = _otherLibTestVectors[i, 0];
236240
string salt;
237241

238242
//Check hash that goes in one end comes out the next the same
239-
salt = _pythonPassLibTestVectors[i, 1];
243+
salt = _otherLibTestVectors[i, 1];
240244

241245
string hashed = BCrypt.HashPassword(plain, salt, enhancedEntropy: true, HashType.SHA256);
242246

243-
Assert.NotEqual(hashed, _pythonPassLibTestVectors[i, 2]);
247+
Assert.NotEqual(hashed, _otherLibTestVectors[i, 2]);
244248

245249
var validateHashCheck = BCrypt.EnhancedVerify(plain, hashed, HashType.SHA256);
246250
Assert.True(validateHashCheck);

0 commit comments

Comments
 (0)