我真的尝试在将问题带到这里之前自行调试问题,但是尽管这似乎是常见问题,但我严重无法找到解决我的laravel auth问题的解决方案。
我的身份验证将无法登录。它总是返回false,我不明白为什么。
我正在尝试使用auth:attempt登录,但无法正常工作。始终处于其他状态。
当身份验证尝试成功时,如果出现其他情况,它将自动进入
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use App\Http\Controllers\Redirect;
use App\User;
use Illuminate\Support\Facades\Auth;
class AdminCreateLogin extends Controller
{
public function addAdmin(Request $request)
{
$name = $request->username;
$password = $request->password;
$password = Hash::make($password);
$email = $request->email;
$user= new User;
$user->name = $name;
$user->password = $password;
$user->email = $email;
$user->save();
}
public function adminLogin(Request $request)
{
$email = $request->email;
$password1 = $request->password;
$password = bcrypt($password1);
//$password = hash:make($password1);
$userdata = array(
'email' => $email,
'password' => $password
);
if(Auth::attempt($userdata))
{
echo "login";
die;
return redirect('/admin/post/list');
}
else
{
echo "login not";
die;
return back()->with('error',"Invalid Login");
}
}
}
请帮助我。
答案 0 :(得分:1)
您不需要手动bcrypt
。 https://laravel.com/docs/7.x/authentication#authenticating-users
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials)) {
// Authentication passed...
return redirect()->intended('dashboard');
}