Published 1 month ago by Farouz

my question related to Validation : now i have $user->password this is the old password how i make a validation for input name='oldPassword' that the user must enter the the old password when reset his password

1 month ago (143,050 XP)


$validator = Validator::make($request->all(), [
    'oldPassword' => [
        function($attribute, $value, $fail) use ($user) {
            if (bcrypt($value) !== $user->password) {
                return $fail($attribute.' is invalid.');
1 month ago (149,860 XP)

In the boot() method of your AppServiceProvider create a validPassword validator:

Validator::extend('validPassword', function($attribute, $value, $parameters) {
    return Hash::check($value, Auth::user()->getAttribute('password'));

Then you can use it in your rules array like this:

"current_password" => "required|validPassword",

And customize the error message in /resources/lang/en/validation.php:

'valid_password' => 'The supplied password is invalid.',

Please sign in or create an account to participate in this conversation.