question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Interoperability issue with PHP implementation (and others) when truncating long password

See original GitHub issue

Hello,

Interoperability is quite important for us, since we have 4 different software developed in different languages (Java, C#, C++, PHP) using the same database.

We have detected a very serious interoperability issue with this library when dealing with long password (and truncating strategy).

If we generate a hash like this:

String hash = BCrypt.with(BCrypt.Version.VERSION_2Y, new SecureRandom(), LongPasswordStrategies.truncate()).hashToString(12, password.toCharArray());

With password =

password_longer_than_72_bytes_abcdefghijklmnopqrstuvwxyz0123456789_abcdefghijklmnopqrstuvwxyz0123456789

We obtain hash = $2y$12$BhmM4lJ91dMTHQoh3XgxY.QZg2j1EfH6DpiwmgufAAHImqCSvA/b.

If we take this hash and try to verify it using PHP (using password_verify()), the check will fail.

You can quickly try it using this handy online tool: https://bcrypt-generator.com image


After looking into the code, we though that the issue could come from the truncating strategy. We tried overriding the MAX_PW_LENGTH_BYTE:

public static final int MAX_PW_LENGTH_BYTE = 72;

The new hash generated was $2y$12$wHUr.PTUQPb7.CsK/0jHq.G4m6uIiHinBDBsWf2/cnwwwANZceQYm

And this one works: image

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Indigo744commented, Oct 22, 2019

Thank you! I’ll look into it.

If you can wait a bit, we have some more tests coming in tomorrow.

0reactions
patrickfavcommented, Oct 29, 2019

#28 is merged

Read more comments on GitHub >

github_iconTop Results From Across the Web

PHP truncating hashed password on retrieval from database
I'm currently having some trouble getting a login system to work and I believe I have found the reason why, though I have...
Read more >
Replace custom password hashing library with PHP 5.5 ...
Problem. The current password hashing library is a custom fork of phpass. It has to be maintained by Drupal. Drupal should not be...
Read more >
Does bcrypt have a maximum password length?
Yes, bcrypt has a maximum password length. The original article contains this: the key argument is a secret encryption key, which can be...
Read more >
HOTP: An HMAC-Based One-Time Password Algorithm
Abstract This document describes an algorithm to generate one-time password values, based on Hashed Message Authentication Code (HMAC).
Read more >
UTR #36: Unicode Security Considerations
This document is organized into two sections: visual security issues and non-visual ... Proper implementation in browsers and other programs is required to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found