How to use hash check to check current password? (In Laravel 5.3)

藏色散人
Release: 2023-04-05 17:56:02
Original
3675 people have browsed it

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.

How to use hash check to check current password? (In Laravel 5.3)

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('在这里,写下你的更新密码');
    }
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!