-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,19 +45,13 @@ public function testCostInRange() | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * @requires PHP 5.3.7 | ||
| */ | ||
| public function testResultLength() | ||
| { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why these two tests were skipped. They work perfectly fine with all PHP versions, and they're not skipped on 2.7.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PHP before 5.3.7 has a broken bcrypt implementation: https://github.com/ircmaxell/password_compat#requirements
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But some <5.3.7 versions have been patched by distribs :)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. then use the password_compat check function to check for support (btw, the library used to trigger an error at runtime, which is probably why the skipping was there)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By the way, that's the reason why tests on Appveyor are failing now (see #17073 for the fix). |
||
| $encoder = new BCryptPasswordEncoder(self::VALID_COST); | ||
| $result = $encoder->encodePassword(self::PASSWORD, null); | ||
| $this->assertEquals(60, strlen($result)); | ||
| } | ||
|
|
||
| /** | ||
| * @requires PHP 5.3.7 | ||
| */ | ||
| public function testValidation() | ||
| { | ||
| $encoder = new BCryptPasswordEncoder(self::VALID_COST); | ||
|
|
@@ -73,13 +67,15 @@ public function testEncodePasswordLength() | |
| { | ||
| $encoder = new BCryptPasswordEncoder(self::VALID_COST); | ||
|
|
||
| $encoder->encodePassword(str_repeat('a', 5000), 'salt'); | ||
| $encoder->encodePassword(str_repeat('a', 73), 'salt'); | ||
| } | ||
|
|
||
| public function testCheckPasswordLength() | ||
| { | ||
| $encoder = new BCryptPasswordEncoder(self::VALID_COST); | ||
| $result = $encoder->encodePassword(str_repeat('a', 72), null); | ||
|
|
||
| $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')); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| } | ||
| } | ||
There was a problem hiding this comment.
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: