I'm new on PHP symfony, I'm working with FOSUserbundle, I created a new view for the user change password but it was so hard to embeded the change password form from the FOSUserBundle so I created manually a html form and add some code in the controller of the view and everything is working fine, the change pasword works on my DB but the problem is that the password is plaintext and I need it encode (encrypt), how do I encode my password to send it to the db?
Here is the form in my twig view:
<form action="{{path ('fos_user_profile_change_password')}}" method="POST" id="form_user_change_password">
<div class="form-group">
<div>
<label for="fos_user_change_password_form_current_password" class="required">Contraseña actual</label>
<input type="password" id="fos_user_change_password_form_current_password" name="fos_user_change_password_form[current_password]" required="required">
</div>
<div>
<label for="new_password" class="required">Nueva contraseña</label>
<input type="password" id="new_password" name="new_password" required="required">
</div>
<div>
<label for="new_password_repeat" class="required">Repita la contraseña</label>
<input type="password" name="new_password_repeat" id="new_password_repeat" required="required">
</div>
<div>
<input type="submit" value="{{ 'change_password.submit'|trans }}" class="btn btn-primary btn-block uppercase" />
</div>
</div>
</form>
and here is my controller:
/**
* Change user password.
*
* @param Request $request
*
* @return Response
*/
public function changePasswordAction(Request $request)
{
$userManager = $this->get('fos_user.user_manager');
$user = $this->getUser();
$new_password = $_POST['new_password'];
$user->setPassword($new_password);
$userManager->updateUser($user);
$url = $this->generateUrl('fos_user_profile_edit');
$response = new RedirectResponse($url);
return $response;
}
Please I'm a newbie on PHP and Symfony3 :)