我试图在登录时检查用户输入密码和数据库中的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。
您的参数顺序不正确。您应该首先添加密码的纯文本版本,如下所示:
Hash::check($data['doctorPassword'], $user->doctorPassword);
我觉得这里一切都好。只需将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');
}