[英]Laravel auth not working using correct username/password combination
For some reason, I'm unable to login with the correct username/password combination. 由于某些原因,我无法使用正确的用户名/密码组合登录。 I'm using flash messages to show when the login information is incorrect.
我使用Flash消息显示登录信息不正确的时间。
I've tried creating multiple accounts to make sure I wasn't actually entering the wrong login credentials, but after about an hour of fiddling it's still not working. 我尝试创建多个帐户,以确保我实际上没有输入错误的登录凭据,但是经过大约一个小时的摆弄后,它仍然无法正常工作。
Any help would be greatly appreciated! 任何帮助将不胜感激! Thank you!
谢谢!
Here's what I got. 这就是我得到的。
UsersController.php (postCreate) - Function that creates my user account (working perfectly fine) UsersController.php(postCreate) -创建我的用户帐户的功能(工作正常)
public function postCreate() {
$rules = array(
'username'=>'required|unique:users,username|alpha_dash|min:4',
'password'=>'required|min:8|confirmed',
'password_confirmation'=>'required|min:8',
'email'=>'required|email|unique:users,email'
);
$input = Input::only(
'username',
'password',
'password_confirmation',
'email'
);
$validator = Validator::make($input, $rules);
if($validator->fails())
{
return Redirect::to('register')->withErrors($validator)->withInput();
}
//$confirmation_code = str_random(30);
User::create(array(
'username'=>Input::get('username'),
'password'=>Hash::make(Input::get('password')),
'email'=>Input::get('email')
//'comfirmation_code' => $confirmation_code
));
// Mail::send('email.verify', function($message) {
// $message->to(Input::get('email'), Input::get('username'))
// ->subject('Verify your email address');
// });
// Flash::message('Thanks for signing up! Please check your email.');
return Redirect::to('login')->with('message', 'Thanks for signing up! Please check your email.');
}
UsersController.php (postLogin) - Function that logs me into account UsersController.php(postLogin) -将我登录到帐户的功能
public function postLogin() {
$user = array(
'email'=>Input::get('email'),
'password'=>Input::get('password')
);
if (Auth::attempt($user)){
return Redirect::intended('account')->with('message', 'Welcome back!');
} else {
return Redirect::to('login')
->with('message', 'Your username/password was incorrect')
->withInput();
}
}
Routes.php Routes.php
Route::get('login', array('as'=>'login', 'uses'=>'UsersController@getLogin'));
Route::post('login', array('before'=>'csrf', 'uses'=>'UsersController@postLogin'));
login.blade.php - My login Page login.blade.php-我的登录页面
@if($errors->has())
<p>The following errors have occured:</p>
<ul id="form-errors">
{{ $errors->first('username', '<li>:message</li>') }}
{{ $errors->first('password', '<li>:message</li>') }}
</ul>
@endif
@if (Session::has('message'))
<p>{{ Session::get('message') }}</p>
@endif
{{ Form::open(array('action'=>'login')) }}
<p>
{{ Form::label('username', 'Username') }}<br />
{{ Form::text('username', Input::old('username')) }}
</p>
<p>
{{ Form::label('password', 'Password') }}<br />
{{ Form::password('password') }}
</p>
<p>
{{ Form::submit('Login') }}
</p>
{{ Form::close() }}
In your 在你的
UsersController.php (postCreate) - : You are able to create using password
with Hash 'password'=>Hash::make(Input::get('password')),
UsersController.php(postCreate) - :您可以创建一个使用
password
进行散列 'password'=>Hash::make(Input::get('password')),
AND 和
UsersController.php (postLogin) : You are trying to login using 'password'=>Input::get('password')
So this should replace with UsersController.php(postLogin) :您尝试使用
'password'=>Input::get('password')
因此应替换为
'password'=>Hash::make(Input::get('password'))
Also hashed passwords required 64 charactters for database field. 另外,哈希密码需要64个字符作为数据库字段。 so check that too.
所以也检查一下。
I found the issue to be with the amount of characters I was allowing to be entered into the password field of the database. 我发现问题出在允许输入数据库的密码字段的字符数。
I had the password column set to: $table->string('password', 32);
我将密码列设置为:
$table->string('password', 32);
varchar(32) which wont work because hashed passwords in laravel require at least 64 characters. varchar(32)无效,因为laravel中的哈希密码至少需要64个字符。
Changing the password column in my database to varchar(64) fixed the issue. 将数据库中的密码列更改为varchar(64)可以解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.