Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1318d3b

Browse filesBrowse files
author
Robin Chalas
committed
bug #31763 [Security\Core] Make SodiumPasswordEncoder validate BCrypt-ed passwords (nicolas-grekas)
This PR was merged into the 4.3 branch. Discussion ---------- [Security\Core] Make SodiumPasswordEncoder validate BCrypt-ed passwords | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #31758 | License | MIT | Doc PR | - Otherwise, the promise of the "auto" mode doesn't work. Commits ------- c0fc456 [Security\Core] Make SodiumPasswordEncoder validate BCrypt-ed passwords
2 parents 89f423f + c0fc456 commit 1318d3b
Copy full SHA for 1318d3b

File tree

Expand file treeCollapse file tree

2 files changed

+11
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+11
-0
lines changed

‎src/Symfony/Component/Security/Core/Encoder/SodiumPasswordEncoder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Encoder/SodiumPasswordEncoder.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ public function isPasswordValid($encoded, $raw, $salt)
8484
return false;
8585
}
8686

87+
if (72 >= \strlen($raw) && 0 === strpos($encoded, '$2')) {
88+
// Accept validating BCrypt passwords for seamless migrations
89+
return password_verify($raw, $encoded);
90+
}
91+
8792
if (\function_exists('sodium_crypto_pwhash_str_verify')) {
8893
return \sodium_crypto_pwhash_str_verify($encoded, $raw);
8994
}

‎src/Symfony/Component/Security/Core/Tests/Encoder/SodiumPasswordEncoderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Tests/Encoder/SodiumPasswordEncoderTest.php
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public function testValidation()
3131
$this->assertFalse($encoder->isPasswordValid($result, 'anotherPassword', null));
3232
}
3333

34+
public function testBCryptValidation()
35+
{
36+
$encoder = new SodiumPasswordEncoder();
37+
$this->assertTrue($encoder->isPasswordValid('$2y$04$M8GDODMoGQLQRpkYCdoJh.lbiZPee3SZI32RcYK49XYTolDGwoRMm', 'abc', null));
38+
}
39+
3440
/**
3541
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
3642
*/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.