Passwords 编码密码easyadmin v3
我有我的用户,我可以从我的管理面板管理,我可以更改密码,但问题是,在数据库中它没有加密。它在数据库中是清晰的,请保存我如何可以这样做,使它不再是?我给你我的用户实体和crud用户,我使用easyadmin v3和symfony 5捆绑包 我的实体用户Passwords 编码密码easyadmin v3,passwords,symfony5,easyadmin,Passwords,Symfony5,Easyadmin,我有我的用户,我可以从我的管理面板管理,我可以更改密码,但问题是,在数据库中它没有加密。它在数据库中是清晰的,请保存我如何可以这样做,使它不再是?我给你我的用户实体和crud用户,我使用easyadmin v3和symfony 5捆绑包 我的实体用户 这可能会有帮助 <?php namespace App\Event\Subscriber; use App\Entity\BackendUser; use Symfony\Component\DependencyInjection\Con
这可能会有帮助
<?php
namespace App\Event\Subscriber;
use App\Entity\BackendUser;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityUpdatedEvent;
class EasyAdminHooksSubscriber implements EventSubscriberInterface {
/**
* @var UserPasswordEncoderInterface
*/
private $passwordEncoder;
/**
* @var ContainerInterface
*/
private $container;
/**
* EasyAdminSubscriber constructor.
*
* @param UserPasswordEncoderInterface $passwordEncoder
* @param ContainerInterface $container
*/
public function __construct(UserPasswordEncoderInterface $passwordEncoder, ContainerInterface $container) {
$this->passwordEncoder = $passwordEncoder;
$this->container = $container;
}
public static function getSubscribedEvents(): array {
return array(
BeforeEntityUpdatedEvent::class => array('preUpdateEntity')
);
}
/**
* @param BeforeEntityUpdatedEvent $event
*
* @noinspection PhpUnused
*/
public function preUpdateEntity(BeforeEntityUpdatedEvent $event) {
$entity = $event->getEntityInstance();
if($entity instanceof BackendUser) {
$this->preUpdateBackendUser($entity);
}
}
/**
* @param BackendUser $be_user
*/
private function preUpdateBackendUser(BackendUser &$be_user) {
$plain_password = $be_user->getPlainPassword();
if(!empty($plain_password)) {
$new_password = $this->passwordEncoder->encodePassword($be_user, $plain_password);
$be_user->setPassword($new_password);
$be_user->setPlainPassword();
}
}
}
您必须将其添加到您的(后端)用户类:`/***@ORM\Column(type=“string”,length=255,nullable=true)*/private$plainPassword`因此,我必须创建一个事件文件夹,创建一个订户文件,并将您提供给我的代码放入,然后我必须在后端添加代码,我的密码将以加密形式返回到我的数据库?