我不知道为什么laravel的身份验证对我不起作用。.我尝试了所有但仍然不起作用,我使用以下代码登录:
$user = User::where('rut', $request->rut)
->where('password', md5($request->password))
->first();
$employee = Employee::where('id_user', $user->id_user)
->first();
$permissions = User_Type_Permission::where('id_user_type', $user->id_user_type)->pluck('id_permission')->toArray();
$request->session()->put('id_user_type', $user->id_user_type);
$request->session()->put('id_branch_office', $employee->branch_office);
$request->session()->put($permissions);
if(Auth::login($user))
{
echo 1;
die();
return redirect('/account');
}
else
{
echo 2;
die();
return redirect('/login');
}
每次返回“ 2”,并且用户不为空,它带有数据库中的值
我也使用过Attempt:
$user = User::where('rut', $request->rut)
->where('password', md5($request->password))
->first();
$employee = Employee::where('id_user', $user->id_user)
->first();
$permissions = User_Type_Permission::where('id_user_type', $user->id_user_type)->pluck('id_permission')->toArray();
$request->session()->put('id_user_type', $user->id_user_type);
$request->session()->put('id_branch_office', $employee->branch_office);
$request->session()->put($permissions);
$credentials = [
'rut' => $user->rut,
'password' => md5($request->password),
];
if(Auth::attempt($credentials))
{
echo 1;
die();
return redirect('/account');
}
else
{
echo 2;
die();
return redirect('/login');
}
它也返回false,登录信息正确,但是Auth根本不起作用,那是什么?
谢谢!
答案 0 :(得分:1)
如果通过bcrypt存储哈希密码,则应删除md5 .. Auth :: attempt()使用数据库中的哈希值自动检查请求中的纯文本密码。 所以代码应该是
$credentials = [
'rut' => $user->rut,
'password' =>$request->password,
];
if(Auth::attempt($credentials))
{
echo 1;
die();
return redirect('/account');
}else{return redirect('/login')}
并将您在顶部编写的所有代码置于真实状态。 你写的是不正确的.. 如果通过身份验证,使我想要的.. 不放代码,然后检查是否通过验证! 希望与您合作! 祝你好运!