Skip to content

Commit 1b11cce

Browse files
Merge branch '4.4' into 5.0
* 4.4: (30 commits) [Security] Check UserInterface::getPassword is not null before calling needsRehash gracefully handle missing event dispatchers Fix TokenStorage::reset not called in stateless firewall [DotEnv] Remove `usePutEnv` property default value [HttpFoundation] get currently session.gc_maxlifetime if ttl doesnt exists Set up typo fix [DependencyInjection] Handle env var placeholders in CheckTypeDeclarationsPass [Cache] fix memory leak when using PhpArrayAdapter [Validator] Allow underscore character "_" in URL username and password [TwigBridge] Update bootstrap_4_layout.html.twig [FrameworkBundle][SodiumVault] Create secrets directory only when needed fix parsing negative octal numbers [SecurityBundle] Passwords are not encoded when algorithm set to \"true\" [DependencyInjection] Resolve expressions in CheckTypeDeclarationsPass [SecurityBundle] Properly escape regex in AddSessionDomainConstraintPass do not validate passwords when the hash is null [DI] fix resolving bindings for named TypedReference [Config] never try loading failed classes twice with ClassExistenceResource [Mailer] Fix SMTP Authentication when using STARTTLS [DI] Fix making the container path-independent when the app is in /app ...
2 parents bee281d + c7b8ea7 commit 1b11cce

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

Authentication/Provider/DaoAuthenticationProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ protected function checkAuthentication(UserInterface $user, UsernamePasswordToke
5555
throw new BadCredentialsException('The presented password cannot be empty.');
5656
}
5757

58+
if (null === $user->getPassword()) {
59+
throw new BadCredentialsException('The presented password is invalid.');
60+
}
61+
5862
$encoder = $this->encoderFactory->getEncoder($user);
5963

6064
if (!$encoder->isPasswordValid($user->getPassword(), $presentedPassword, $user->getSalt())) {

Encoder/UserPasswordEncoder.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public function encodePassword(UserInterface $user, string $plainPassword)
4242
*/
4343
public function isPasswordValid(UserInterface $user, string $raw)
4444
{
45+
if (null === $user->getPassword()) {
46+
return false;
47+
}
48+
4549
$encoder = $this->encoderFactory->getEncoder($user);
4650

4751
return $encoder->isPasswordValid($user->getPassword(), $raw, $user->getSalt());
@@ -52,6 +56,10 @@ public function isPasswordValid(UserInterface $user, string $raw)
5256
*/
5357
public function needsRehash(UserInterface $user): bool
5458
{
59+
if (null === $user->getPassword()) {
60+
return false;
61+
}
62+
5563
$encoder = $this->encoderFactory->getEncoder($user);
5664

5765
return $encoder->needsRehash($user->getPassword());

Tests/Authentication/Provider/DaoAuthenticationProviderTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ public function testCheckAuthenticationWhenCredentialsAre0()
147147
->willReturn('0')
148148
;
149149

150-
$method->invoke($provider, new TestUser(), $token);
150+
$method->invoke(
151+
$provider,
152+
new User('username', 'password'),
153+
$token
154+
);
151155
}
152156

153157
public function testCheckAuthenticationWhenCredentialsAreNotValid()
@@ -169,7 +173,7 @@ public function testCheckAuthenticationWhenCredentialsAreNotValid()
169173
->willReturn('foo')
170174
;
171175

172-
$method->invoke($provider, new TestUser(), $token);
176+
$method->invoke($provider, new User('username', 'password'), $token);
173177
}
174178

175179
public function testCheckAuthenticationDoesNotReauthenticateWhenPasswordHasChanged()
@@ -241,7 +245,7 @@ public function testCheckAuthentication()
241245
->willReturn('foo')
242246
;
243247

244-
$method->invoke($provider, new TestUser(), $token);
248+
$method->invoke($provider, new User('username', 'password'), $token);
245249
}
246250

247251
public function testPasswordUpgrades()

Validator/Constraints/UserPasswordValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function validate($password, Constraint $constraint)
5353

5454
$encoder = $this->encoderFactory->getEncoder($user);
5555

56-
if (!$encoder->isPasswordValid($user->getPassword(), $password, $user->getSalt())) {
56+
if (null === $user->getPassword() || !$encoder->isPasswordValid($user->getPassword(), $password, $user->getSalt())) {
5757
$this->context->addViolation($constraint->message);
5858
}
5959
}

0 commit comments

Comments
 (0)