4
我最近开始学习Laravel(PHP MVC框架),并且用Auth :: attempt($ credentials)对用户进行身份验证时遇到了很多问题。Laravel Auth :: attempt()总是假?
我会把我的代码片段放在下面。在mySQL数据库中,我有一个记录,其中包含以下键=>值: id => 1,username =>'admin',password =>'admin',created_at => 0000-00-00 00:00:00, updated_at => 0000-00-00 00:00:00
验证程序通过,但验证:尝试始终失败。
如果下面的代码和我的小解释不够,请让我知道! :-)
routes.php文件:
Route::get('login', '[email protected]');
Route::post('login', '[email protected]');
AuthController:
public function showLogin(){
if(Auth::check()){
//Redirect to their home page
}
//Not logged in
return View::make('auth/login');
}
public function postLogin(){
$userData = array(
'username' => Input::get('username'),
'password' => Input::get('password')
);
$reqs = array(
'username' => 'Required',
'password' => 'Required'
);
$validator = Validator::make($userData, $reqs);
if($validator->passes() && Auth::attempt($userData)){
return Redirect::to('home');
}
return Redirect::to('login')->withInput(Input::except('password'));
}
它的工作!我回滚了所有的迁移,对所有密码进行了Hash :: make变更,并进行了迁移。你是一个拯救生命的人! :D – xDranik
甜蜜,很高兴我能帮上忙! :)如果你可以选择正确的答案,这将是很好的,所以我得到一些声誉:D – madshvero
你走了!再次感谢:) – xDranik