Skip to content

Commit eadb3f0

Browse files
authored
don't create a salt for self-salting password encoders
Symfony marks `PasswordEncoderInterface` implementations that generate the salt themselves with `SelfSaltingEncoderInterface` since version 3.4. We can use this in `PasswordUpdater` to skip the salt generation for those encoders, the same way we skip it for `BCryptPasswordEncoder`.
1 parent 5d21457 commit eadb3f0

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Util/PasswordUpdater.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use FOS\UserBundle\Model\UserInterface;
1515
use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder;
1616
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
17+
use Symfony\Component\Security\Core\Encoder\SelfSaltingEncoderInterface;
1718

1819
/**
1920
* Class updating the hashed password in the user when there is a new password.
@@ -39,7 +40,7 @@ public function hashPassword(UserInterface $user)
3940

4041
$encoder = $this->encoderFactory->getEncoder($user);
4142

42-
if ($encoder instanceof BCryptPasswordEncoder) {
43+
if ($encoder instanceof BCryptPasswordEncoder || $encoder instanceof SelfSaltingEncoderInterface) {
4344
$user->setSalt(null);
4445
} else {
4546
$salt = rtrim(str_replace('+', '.', base64_encode(random_bytes(32))), '=');

0 commit comments

Comments
 (0)