Upgrade password when a better method is available.

This commit is contained in:
Jan Böhmer 2019-11-30 15:28:09 +01:00
parent 6a0d027675
commit 05870caf85

View file

@ -28,6 +28,8 @@ use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Mapping; use Doctrine\ORM\Mapping;
use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\NonUniqueResultException;
use Symfony\Bridge\Doctrine\RegistryInterface; use Symfony\Bridge\Doctrine\RegistryInterface;
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/** /**
* @method User|null find($id, $lockMode = null, $lockVersion = null) * @method User|null find($id, $lockMode = null, $lockVersion = null)
@ -35,7 +37,7 @@ use Symfony\Bridge\Doctrine\RegistryInterface;
* @method User[] findAll() * @method User[] findAll()
* @method User[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) * @method User[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/ */
class UserRepository extends EntityRepository class UserRepository extends EntityRepository implements PasswordUpgraderInterface
{ {
protected $anonymous_user; protected $anonymous_user;
@ -80,4 +82,15 @@ class UserRepository extends EntityRepository
return null; return null;
} }
} }
/**
* @inheritDoc
*/
public function upgradePassword(UserInterface $user, string $newEncodedPassword): void
{
if ($user instanceof User) {
$user->setPassword($newEncodedPassword);
$this->getEntityManager()->flush($user);
}
}
} }