Skip to content
Advertisement

How to validate current, new, and new password confirmation in Laravel 5?

I have created the password route, view and method in UserController@getProfilePassword and UserController@postProfilePassword

At the moment, if I fill out the new_password field, it gets hashed and submitted to the database correctly, then I can login with the new password.

But I need to be able to validate the new_password and new_password_confirm to make sure they’re the same and validate the user’s current password as well.

How can I do that?

EDIT: I added $this->validate to the method, but now I keep getting the error The password confirmation confirmation does not match. even though they do match as I am using a simple password. Also I think I need to check against the current password manually as validator won’t do it for me.

JavaScript

And this is the view

JavaScript

Advertisement

Answer

There’s a Hash::check() function which allows you to check whether the old password entered by user is correct or not.

usage

JavaScript

it will return true if old password has been entered correctly and you can add your logic accordingly

for new_password and new_confirm_password to be same, you can add your validation in form request like

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement