Home>Article>Backend Development> How to use hash check to check current password? (In Laravel 5.3)
Sometimes when we change the password function, we need to check the current password first. Of course if the current password does not match, the error "Your old password is wrong" will be returned.
For example, we have a form with three input fields, as follows:
1) Current password
2) New password
3) Confirm the new password
When it will submit the form, we must check if the current password matches the storage database table password. Laravel stores hashed passwords, so we cannot directly perform judgment checks, but laravel provides the Hash facade, and the hash::check() method will help you complete this task.
The following is a simple example for you:
Example:
public function changePassword(Request $request) { $input = $request->all(); $user = User::find(auth()->user()->id); if(!Hash::check($input['current_password'], $user->password)){ dd('返回错误,与当前密码不匹配。'); }else{ dd('在这里,写下你的更新密码'); } }
This article is about the method of using hash check to check the current password in Laravel 5.3. Simple and easy to understand, I hope it will be helpful to friends in need!
The above is the detailed content of How to use hash check to check current password? (In Laravel 5.3). For more information, please follow other related articles on the PHP Chinese website!