Skip to content

Commit b8a80db

Browse files
committed
Avoid relying on the getSalt method when using UserInterface
This method is not guaranted to be there if the Symfony interface does not include it (which it won't do on Symfony 6).
1 parent 1529f2e commit b8a80db

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

Util/HashingPasswordUpdater.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ public function hashPassword(UserInterface $user)
4040
$hasher = $this->passwordHasherFactory->getPasswordHasher($user);
4141

4242
if (!$hasher instanceof LegacyPasswordHasherInterface) {
43-
$user->setSalt(null);
43+
$salt = null;
4444
} else {
4545
$salt = rtrim(str_replace('+', '.', base64_encode(random_bytes(32))), '=');
46-
$user->setSalt($salt);
4746
}
4847

49-
$hashedPassword = $hasher->hash($plainPassword, $user->getSalt());
48+
$user->setSalt($salt);
49+
50+
$hashedPassword = $hasher->hash($plainPassword, $salt);
5051
$user->setPassword($hashedPassword);
5152
$user->eraseCredentials();
5253
}

Util/PasswordUpdater.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ public function hashPassword(UserInterface $user)
4141
$encoder = $this->encoderFactory->getEncoder($user);
4242

4343
if ($encoder instanceof BCryptPasswordEncoder || $encoder instanceof SelfSaltingEncoderInterface) {
44-
$user->setSalt(null);
44+
$salt = null;
4545
} else {
4646
$salt = rtrim(str_replace('+', '.', base64_encode(random_bytes(32))), '=');
47-
$user->setSalt($salt);
4847
}
48+
$user->setSalt($salt);
4949

50-
$hashedPassword = $encoder->encodePassword($plainPassword, $user->getSalt());
50+
$hashedPassword = $encoder->encodePassword($plainPassword, $salt);
5151
$user->setPassword($hashedPassword);
5252
$user->eraseCredentials();
5353
}

0 commit comments

Comments
 (0)