From 864cefbc7a34d3b313019f2c415e2a27d81ff4bd Mon Sep 17 00:00:00 2001 From: Zairig Imad Date: Tue, 9 Jun 2020 22:46:45 +0200 Subject: [PATCH] Update the Snippet with the UserUpgraderInterface --- security/user_provider.rst | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/security/user_provider.rst b/security/user_provider.rst index 13e6a8dfb49..07227868afe 100644 --- a/security/user_provider.rst +++ b/security/user_provider.rst @@ -356,10 +356,11 @@ command will generate a nice skeleton to get you started:: use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; + use Symfony\Component\Security\Core\User\PasswordUpgraderInterface; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserProviderInterface; - class UserProvider implements UserProviderInterface + class UserProvider implements UserProviderInterface, PasswordUpgraderInterface { /** * Symfony calls this method if you use features like switch_user @@ -412,6 +413,16 @@ command will generate a nice skeleton to get you started:: { return User::class === $class || is_subclass_of($class, User::class); } + + /** + * Upgrades the encoded password of a user, typically for using a better hash algorithm. + */ + public function upgradePassword(UserInterface $user, string $newEncodedPassword): void + { + // TODO: when encoded passwords are in use, this method should: + // 1. persist the new password in the user storage + // 2. update the $user object with $user->setPassword($newEncodedPassword); + } } Most of the work is already done! Read the comments in the code and update the