Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Security] Verify if a password encoded with bcrypt is no longer than 72 characters #17055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 18, 2015

Conversation

jakzal
Copy link
Contributor

@jakzal jakzal commented Dec 17, 2015

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #17047
License MIT
Doc PR -

From the password_hash() docs:

Caution Using the PASSWORD_BCRYPT as the algorithm, will result in the password parameter being truncated to a maximum length of 72 characters.


$this->assertFalse($encoder->isPasswordValid('encoded', str_repeat('a', 5000), 'salt'));
$this->assertFalse($encoder->isPasswordValid($result, str_repeat('a', 73), 'salt'));
$this->assertTrue($encoder->isPasswordValid($result, str_repeat('a', 72), 'salt'));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We didn't have this assertion before. Without this there could be no length validation in isPasswordValid() and the assertion on the line before would pass anyway.

@nicolas-grekas
Copy link
Member

👍

@@ -19,6 +19,8 @@
*/
class BCryptPasswordEncoder extends BasePasswordEncoder
{
const MAX_PASSWORD_LENGTH = 72;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could add a comment above this constant to show that this limit is not arbitrary. Something like this:

// When using bcrypt algorithm, PHP's password_hash() truncates the password length to a maximum of 72 chars.
const MAX_PASSWORD_LENGTH = 72;

@fabpot
Copy link
Member

fabpot commented Dec 18, 2015

Thank you @jakzal.

@fabpot fabpot merged commit 0a496e7 into symfony:2.3 Dec 18, 2015
fabpot added a commit that referenced this pull request Dec 18, 2015
…longer than 72 characters (jakzal)

This PR was merged into the 2.3 branch.

Discussion
----------

[Security] Verify if a password encoded with bcrypt is no longer than 72 characters

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17047
| License       | MIT
| Doc PR        | -

From the [password_hash() docs](http://php.net/password_hash):

> Caution Using the PASSWORD_BCRYPT as the algorithm, will result in the password parameter being truncated to a maximum length of 72 characters.

Commits
-------

0a496e7 [Security] Enable bcrypt validation and result length tests on all PHP versions
5c30266 [Security] Verify if a password encoded with bcrypt is no longer than 72 characters
@jakzal jakzal deleted the security/bcrypt-password-length branch December 20, 2015 10:44
nicolas-grekas added a commit that referenced this pull request Dec 22, 2015
…Christian Flothmann, xabbuh)

This PR was merged into the 2.3 branch.

Discussion
----------

[Security] skip bcrypt tests on incompatible platforms

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17055
| License       | MIT
| Doc PR        |

Not all PHP versions before 5.3.7 have backported fixes that make it
possible to use `password_hash()` function. Therefore, we have to skip
tests on not supported platforms.

Commits
-------

2a6fa7b use requires annotation
65eb188 skip bcrypt tests on incompatible platforms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants