我尝试过以下代码。但是auth尝试失败了。
// validate the info, create rules for the inputs
$rules = array(
'email' => 'required|email', // make sure the email is an actual email
'password' => 'required|alphaNum|min:3' // password can only be alphanumeric and has to be greater than 3 characters
);
// run the validation rules on the inputs from the form
$validator = Validator::make(Input::all(), $rules);
// if the validator fails, redirect back to the form
if ($validator->fails()) {
return Redirect::to('login')
->withErrors($validator) // send back all errors to the login form
->withInput(Input::except('password')); // send back the input (not the password) so that we can repopulate the form
} else {
// create our user data for the authentication
$userdata = array(
'Email' => Input::get('email'),
'Password' => Input::get('password')
);
// attempt to do the login
if (Auth::attempt($userdata)) {
// validation successful!
// redirect them to the secure section or whatever
// return Redirect::to('secure');
// for now we'll just echo success (even though echoing in a controller is bad)
echo 'SUCCESS!';
} else {
// validation not successful, send back to form
return Redirect::to('login')->with('message', 'Login Failed');
}
}
我在Users表中有以下列。
ID, 用户名, 电子邮件, created_at, 的updated_at, 密码
我在模型中更改了表名。请指教。怎么了?
答案 0 :(得分:1)
通常,惯例是将数据库列设为小写。使用电子邮件列,这应该不是问题。如文档所述,'email'
字段仅用作示例。 http://laravel.com/docs/security#authenticating-users
使Laravel使用您的大写密码列。打开用户雄辩的模型并进行更改:
public function getAuthPassword()
{
return $this->password;
}
为:
public function getAuthPassword()
{
return $this->Password;
}
非常确定能够做到这一点,