2 回答
TA贡献1854条经验 获得超8个赞
您可以使用UserPasswordEncoderInterface清楚地散列您的密码,例如:
.....
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
......
class UserService implements UserServiceInterface
{
private $userPasswordEncoderInterface;
private $entityManager;
public function __construct(
UserPasswordEncoderInterface $userPasswordEncoderInterface,
EntityManagerInterface $entityManager)
{
$this->userPasswordEncoderInterface = $userPasswordEncoderInterface;
$this->entityManager = $entityManager;
}
public function save(User $user): Response
{
$passwordHash = $this->userPasswordEncoderInterface->encodePassword($user, $user->getPassword());
$user->setPassword($passwordHash);
$this->entityManager->persist($user);
$this->entityManager->flush();
return new Response('password encoded');
}
}
- 2 回答
- 0 关注
- 920 浏览
添加回答
举报