我正在使用laravel手動身份驗證系統。提交表單重定向到此路由如下所示。而在authenticate()函數中,名稱和密碼永遠不會與我先前存儲的名稱和密碼匹配。即Auth::attempt
總是錯誤的。Laravel手動身份驗證:身份驗證::嘗試始終爲假
Route::post('/logintest', '[email protected]');
Route::get('/home', ['middleware' => 'auth', function() {
echo "home page";});
}]);
身份驗證功能:
public function authenticate(Request $request)
{
$input=$request->all();
$password=$input['password'];
$name=$input['name'];
if (Auth::attempt(['Name' => $name, 'Password' => $password])){
return redirect()->intended('/home');
} else
{
return redirect('/login')->with('message','Error logging in!');
}
}
我已經註冊了用戶這種方式。密碼使用bcrypt()散列。功能。但在authenticate()函數中,我正在與純密碼進行比較。我在某處讀Auth
會自動處理它。或者有什麼我應該改變在config/auth.php,因爲我用名稱進行身份驗證,而不是用戶名?
public function register(Request $request)
{
$input=$request->all();
$password=bcrypt($input['password']);
$name=$input['name'];
$insert= User::insert(['Name'=>$name,'Password'=>$password]);
return redirect('/login')
->with('message','successfully Registered.');
}
你能告訴我們路線文件嗎? – VipindasKS
@VipindasKS我已經把它們顯示在頂部。 – micky
這是唯一定義的路線。只是想確保它不與任何其他路線衝突。特別是,如果你早先做過一個php工匠make:auth。 – VipindasKS