Skip to content

Commit

Permalink
[Security] Verify if a password encoded with bcrypt is no longer than…
Browse files Browse the repository at this point in the history
… 72 characters
  • Loading branch information
jakzal committed Dec 17, 2015
1 parent b23c9a3 commit 5c30266
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Expand Up @@ -19,6 +19,8 @@
*/
class BCryptPasswordEncoder extends BasePasswordEncoder
{
const MAX_PASSWORD_LENGTH = 72;

/**
* @var string
*/
Expand Down
Expand Up @@ -95,6 +95,6 @@ protected function comparePasswords($password1, $password2)
*/
protected function isPasswordTooLong($password)
{
return strlen($password) > self::MAX_PASSWORD_LENGTH;
return strlen($password) > static::MAX_PASSWORD_LENGTH;
}
}
Expand Up @@ -73,13 +73,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'));
}
}

0 comments on commit 5c30266

Please sign in to comment.