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?
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.
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.
You should use Hash::check( $plaintext, $hashed )
instead:
return Hash::check( $value, $user->password );
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