Я пытаюсь сделать забытую функцию пароля в моем приложении Symfony 3.1. Неправильно.// retrieve the user
$user = $this->getDoctrine()->getRepository("AppBundle:User")->findOneBy(array('username' => "admin", "token" => $token));
//the password posted from the form
$password = $request->get('new_password');
$em = $this->getDoctrine()->getManager();
//encoding it according to the symfony doc
//see https://symfony.com/doc/3.1/security/pa ... oding.html
$encoder = $this->container->get('security.password_encoder');
$encoded = $encoder->encodePassword($user, $password);
//updating the password in the database
$user->setPassword($encoded);
$em->persist($user);
$em->flush();
< /code>
У меня есть набор энкодера в моем файле безопасности.encoders:
Symfony\Component\Security\Core\User\User:
algorithm: bcrypt
AppBundle\Entity\User:
algorithm: bcrypt
< /code>
брандмауэр в Security.yaml: < /p>
firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: ~
form_login:
login_path: /admin/connexion
check_path: /admin/connexion
logout:
path: /logout
target: /
< /code>
Свойство пароля в классе user.php: < /p>
/**
* @var string
*/
private $password;
Поле пароля в config/doctrine/user.orm.xml:
Подробнее здесь: https://stackoverflow.com/questions/546 ... ord-update