Hash :: check()总是返回false

问题描述 投票:2回答:2

我试图在登录时检查用户输入密码和数据库中的Hashed密码,但它总是返回false。

这是控制器哈希密码中的代码

$doctor = new doctor;
    $doctor->name = $request->name;
    $doctor->address = $request->address;
    $doctor->email = $request->email;
    $doctor->mobile = $request->mobile;
    $password = Hash::make($request->doctorPassword);
    $doctor->doctorPassword = $password;

这是用于验证密码的代码:$ data = $ request-> all();

    $user = doctor::where('email',$data['doctorUsername'])->first();
    if ($user) {

        if (Hash::check($user->doctorPassword, $data['doctorPassword']))
        {
            return view($this->filePath . '.doctorProfile');
        }

}

始终返回false。

laravel hash passwords
2个回答
5
投票

您的参数顺序不正确。您应该首先添加密码的纯文本版本,如下所示:

Hash::check($data['doctorPassword'], $user->doctorPassword);

0
投票

我觉得这里一切都好。只需将hashedPassword $user->doctorPassword作为Hash :: check()中的第二个参数。干杯:D

$user = doctor::where('email',$data['doctorUsername'])->first();
    if ($user) {

        if (Hash::check($data['doctorPassword'], $user->doctorPassword))
        {
            return view($this->filePath . '.doctorProfile');
        }

请检查以下链接:https://laravel.com/docs/5.8/hashing

© www.soinside.com 2019 - 2024. All rights reserved.