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.
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)
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
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
Route::get('login', array('as'=>'login', 'uses'=>'UsersController@getLogin'));
Route::post('login', array('before'=>'csrf', 'uses'=>'UsersController@postLogin'));
login.blade.php - My login Page
@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')),
AND
UsersController.php (postLogin) : You are trying to login using 'password'=>Input::get('password')
So this should replace with
'password'=>Hash::make(Input::get('password'))
Also hashed passwords required 64 charactters for database field. 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);
varchar(32) which wont work because hashed passwords in laravel require at least 64 characters.
Changing the password column in my database to varchar(64) fixed the issue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.