I have a need to manually encrypt the password in the same way Symfony does it.
$user->setPlainPassword($password);
$userManager->updateUser($user);
This is application code that saves the user password. But it is obviously encrypted (not plain as method says).
How can I manually get the same result for given password?
EDIT1:
The problem is that I want to authenticate user manually in users controller code. I have readable username and password that comes as parameters. I want to return 401 if they to not exist in database.
Symfony comes with a useful command to encode a password the same way it does:
bin/console security:encode-password 'your_plain_password' 'AppBundle\Entity\YourUserClass'
Try this in your controller action:
$encoder = $this->get('security.encoder_factory')->getEncoder($userClass);
$encodedPassword = $encoder->encodePassword($plainPassword);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With