Skip to content

Commit

Permalink
[AdminBundle] Enable automatic password upgrades by symfony security/…
Browse files Browse the repository at this point in the history
…hashers
  • Loading branch information
acrobat committed Oct 6, 2022
1 parent 2c47b42 commit 32e19b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Kunstmaan/AdminBundle/Entity/BaseUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
use Kunstmaan\AdminBundle\Validator\Constraints\PasswordRestrictions;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface as BaseUserInterface;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Mapping\ClassMetadata;

abstract class BaseUser implements UserInterface, EquatableInterface
abstract class BaseUser implements UserInterface, EquatableInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
Expand Down
11 changes: 10 additions & 1 deletion src/Kunstmaan/AdminBundle/Repository/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
namespace Kunstmaan\AdminBundle\Repository;

use Doctrine\ORM\EntityRepository;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;

/**
* UserRepository
*/
class UserRepository extends EntityRepository
class UserRepository extends EntityRepository implements PasswordUpgraderInterface
{
/**
* Get user(s) that have the specified role(s)
Expand Down Expand Up @@ -36,4 +38,11 @@ public function getUsersByRole($role)

return $qb->getQuery()->getResult();
}

public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newEncodedPassword): void
{
$user->setPassword($newEncodedPassword);

$this->getEntityManager()->flush();
}
}

0 comments on commit 32e19b3

Please # to comment.