Skip to content

Commit 68bd2c1

Browse files
committed
bug symfony#17055 [Security] Verify if a password encoded with bcrypt is no 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 | symfony#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
2 parents baa5b7d + 0a496e7 commit 68bd2c1

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

src/Symfony/Component/Security/Core/Encoder/BCryptPasswordEncoder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*/
2020
class BCryptPasswordEncoder extends BasePasswordEncoder
2121
{
22+
const MAX_PASSWORD_LENGTH = 72;
23+
2224
/**
2325
* @var string
2426
*/

src/Symfony/Component/Security/Core/Encoder/BasePasswordEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,6 @@ protected function comparePasswords($password1, $password2)
9595
*/
9696
protected function isPasswordTooLong($password)
9797
{
98-
return strlen($password) > self::MAX_PASSWORD_LENGTH;
98+
return strlen($password) > static::MAX_PASSWORD_LENGTH;
9999
}
100100
}

src/Symfony/Component/Security/Tests/Core/Encoder/BCryptPasswordEncoderTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,13 @@ public function testCostInRange()
4545
}
4646
}
4747

48-
/**
49-
* @requires PHP 5.3.7
50-
*/
5148
public function testResultLength()
5249
{
5350
$encoder = new BCryptPasswordEncoder(self::VALID_COST);
5451
$result = $encoder->encodePassword(self::PASSWORD, null);
5552
$this->assertEquals(60, strlen($result));
5653
}
5754

58-
/**
59-
* @requires PHP 5.3.7
60-
*/
6155
public function testValidation()
6256
{
6357
$encoder = new BCryptPasswordEncoder(self::VALID_COST);
@@ -73,13 +67,15 @@ public function testEncodePasswordLength()
7367
{
7468
$encoder = new BCryptPasswordEncoder(self::VALID_COST);
7569

76-
$encoder->encodePassword(str_repeat('a', 5000), 'salt');
70+
$encoder->encodePassword(str_repeat('a', 73), 'salt');
7771
}
7872

7973
public function testCheckPasswordLength()
8074
{
8175
$encoder = new BCryptPasswordEncoder(self::VALID_COST);
76+
$result = $encoder->encodePassword(str_repeat('a', 72), null);
8277

83-
$this->assertFalse($encoder->isPasswordValid('encoded', str_repeat('a', 5000), 'salt'));
78+
$this->assertFalse($encoder->isPasswordValid($result, str_repeat('a', 73), 'salt'));
79+
$this->assertTrue($encoder->isPasswordValid($result, str_repeat('a', 72), 'salt'));
8480
}
8581
}

0 commit comments

Comments
 (0)