Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 - validator for current user password

I have password change form and there's two fields in it: old_password and new_password.

I'm stuck with validator for old password, here's what I done:

Validator::extend('old_password', function($attribute, $value) use ($user) {
    return $user->password === Hash::make($value);
});

But Hash::make($value) always generates different result with the same $value.

How can I make validator to match current user password?

like image 324
Limon Monte Avatar asked Apr 17 '15 08:04

Limon Monte


People also ask

How does laravel validate current password?

The $this->current_password gives us the current_password form field value whereas Laravel allows us to access the currently authenticated user using $this->user() so $this->user()->password gives us the user's hashed password saved in the database. The two passwords are compared using the Hash facade's check method.

What are the validations for password?

The password must contain one or more uppercase characters. The password must contain one or more lowercase characters. The password must contain one or more numeric values. The password must contain one or more special characters.


1 Answers

You should use Hash::check( $plaintext, $hashed ) instead:

return Hash::check( $value, $user->password );
like image 152
Joe Avatar answered Sep 28 '22 12:09

Joe