Skip to content

Commit fef4012

Browse files
Merge branch '5.0'
* 5.0: [VarDumper] fix for change in PHP 7.4.6 Added regression test for AccountStatusException behavior (ref #36822) [HttpClient] fix PHP warning + accept status code >= 600 [Security/Core] fix compat of `NativePasswordEncoder` with pre-PHP74 values of `PASSWORD_*` consts embed resource name in error message [FrameworkBundle] fix stringable annotation Change priority of KernelEvents::RESPONSE subscriber Fix register event listeners compiler pass Missing description in `messenger:setup-transports` command [Serializer] fix issue with PHP 8 [WebProfiler] Remove 'none' when appending CSP tokens [TwigBundle] FormExtension does not have a constructor anymore since sf 4.0 [Yaml] Fix escaped quotes in quoted multi-line string
2 parents afc9390 + 0453928 commit fef4012

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

Encoder/NativePasswordEncoder.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class NativePasswordEncoder implements PasswordEncoderInterface, SelfSalti
2424
{
2525
private const MAX_PASSWORD_LENGTH = 4096;
2626

27-
private $algo;
27+
private $algo = PASSWORD_BCRYPT;
2828
private $options;
2929

3030
/**
@@ -48,7 +48,20 @@ public function __construct(int $opsLimit = null, int $memLimit = null, int $cos
4848
throw new \InvalidArgumentException('$cost must be in the range of 4-31.');
4949
}
5050

51-
$this->algo = (string) ($algo ?? (\defined('PASSWORD_ARGON2ID') ? PASSWORD_ARGON2ID : (\defined('PASSWORD_ARGON2I') ? PASSWORD_ARGON2I : PASSWORD_BCRYPT)));
51+
$algos = [1 => PASSWORD_BCRYPT, '2y' => PASSWORD_BCRYPT];
52+
53+
if (\defined('PASSWORD_ARGON2I')) {
54+
$this->algo = $algos[2] = $algos['argon2i'] = (string) PASSWORD_ARGON2I;
55+
}
56+
57+
if (\defined('PASSWORD_ARGON2ID')) {
58+
$this->algo = $algos[3] = $algos['argon2id'] = (string) PASSWORD_ARGON2ID;
59+
}
60+
61+
if (null !== $algo) {
62+
$this->algo = $algos[$algo] ?? $algo;
63+
}
64+
5265
$this->options = [
5366
'cost' => $cost,
5467
'time_cost' => $opsLimit,

Tests/Authentication/AuthenticationProviderManagerTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,16 @@ public function testAuthenticateWhenNoProviderSupportsToken()
5454

5555
public function testAuthenticateWhenProviderReturnsAccountStatusException()
5656
{
57+
$secondAuthenticationProvider = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface')->getMock();
58+
5759
$manager = new AuthenticationProviderManager([
5860
$this->getAuthenticationProvider(true, null, 'Symfony\Component\Security\Core\Exception\AccountStatusException'),
61+
$secondAuthenticationProvider,
5962
]);
6063

64+
// AccountStatusException stops authentication
65+
$secondAuthenticationProvider->expects($this->never())->method('supports');
66+
6167
try {
6268
$manager->authenticate($token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
6369
$this->fail();

Tests/Encoder/NativePasswordEncoderTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ public function testConfiguredAlgorithm()
7373
$this->assertStringStartsWith('$2', $result);
7474
}
7575

76+
public function testConfiguredAlgorithmWithLegacyConstValue()
77+
{
78+
$encoder = new NativePasswordEncoder(null, null, null, '1');
79+
$result = $encoder->encodePassword('password', null);
80+
$this->assertTrue($encoder->isPasswordValid($result, 'password', null));
81+
$this->assertStringStartsWith('$2', $result);
82+
}
83+
7684
public function testCheckPasswordLength()
7785
{
7886
$encoder = new NativePasswordEncoder(null, null, 4);

0 commit comments

Comments
 (0)