【发布时间】:2013-02-27 10:36:23
【问题描述】:
这是我的问题:
我有一个表 users 是:
id 用户名邮箱密码
另外,一个模型用户,在注册时,一切都很好。
现在当我想登录时,这是我的视图:
@layout('main')
@section('content')
@if(Session::has('login_errors'))
<div class='alert alert-error'>Wrong ID</div>
@endif
{{Form::open('user/login', 'POST', array('class' => 'well inline-form'))}}
{{Form::token()}}
{{Form::text('username', Input::old('username'), array('class' => 'input-large', 'placeholder' => 'email'))}}
{{Form::password('password', array('class' => 'input-large', 'placeholder' => 'Mot de passe'))}}
{{Form::submit('Login', array('class'=>'btn btn-primary'))}}
{{Form::close()}}
@endsection
这是我在控制器
中所做的public function action_login()
{
if(Auth::check()){return Redirect::to('user');}
if(Request::method() == 'POST')
{
$credentials = array('username' => Input::get('username'), 'password' => Input::get('password'));
if(Auth::attempt($credentials))
{
return Redirect::to('user');
}
else
{
return Redirect::to('user/login')->with_input()->with('login_errors', true);
}
}
Section::inject('title', 'Login');
return View::make('user.login');
}
它应该工作,但它没有。
错误如下:当我单击登录按钮时,我的表单传递给我的控制器并被读取。我知道我的 Input::get('username'), Input::get('password') 是正确的,并在 db 中注册。
问题是:即使我的电子邮件/密码是正确的,我也无法获得身份验证,并且我收到了我的消息错误的 ID。我希望我很清楚......
你应该知道的事情:
我没有更改配置中的Auth.php,所以用户名是电子邮件
我在注册时对密码进行哈希处理:'password' => Hash::make(Input::get('password'))
编辑和解决方案
好的,我想通了!
首先:
- 我用的是 PHP 5.3.6,Hash 至少需要 5.3.7
- 之后,我意识到在我的数据库中,密码最多为 40 个字符。我觉得自己很蠢
希望它会帮助某人/线程
【问题讨论】:
-
你能提供你的路线吗?
-
我的路由真的很简单:Route::controller(Controller::detect());