Skip to content

Commit f90dccb

Browse files
authored
Update the Snippet with the UserUpgraderInterface
1 parent 839ab90 commit f90dccb

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

security/user_provider.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,11 @@ command will generate a nice skeleton to get you started::
355355

356356
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
357357
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
358+
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
358359
use Symfony\Component\Security\Core\User\UserInterface;
359360
use Symfony\Component\Security\Core\User\UserProviderInterface;
360361

361-
class UserProvider implements UserProviderInterface
362+
class UserProvider implements UserProviderInterface, PasswordUpgraderInterface
362363
{
363364
/**
364365
* Symfony calls this method if you use features like switch_user
@@ -411,6 +412,16 @@ command will generate a nice skeleton to get you started::
411412
{
412413
return User::class === $class;
413414
}
415+
416+
/**
417+
* Upgrades the encoded password of a user, typically for using a better hash algorithm.
418+
*/
419+
public function upgradePassword(UserInterface $user, string $newEncodedPassword): void
420+
{
421+
// TODO: when encoded passwords are in use, this method should:
422+
// 1. persist the new password in the user storage
423+
// 2. update the $user object with $user->setPassword($newEncodedPassword);
424+
}
414425
}
415426

416427
Most of the work is already done! Read the comments in the code and update the

0 commit comments

Comments
 (0)