It says that the page isn't redirecting properly, because you are creating a loop here.$this->beforeFilter('auth');
will be fired on every method of controller so if you try to reach /login
the filter will fire, check that you are not logged in and then try to redirect you to /login
route. And over and over again. So applying an auth
filter to the controller thats purpose is to actually log you in is pointless. Did not check your code, but this line may be a problem
{{Form::open()}}
{{ Form::open(array('url' => 'login')) }} //correct
Try it out and eventually let me know.
@zaalbarxx You 're right about the loop, because when I try to login it does take some time. Also checked it with NetBeans, and yes there is a repeating loop when I try to login. In login.blade.php I replaced:
{{Form::open()}}
with
{{ Form::open(array('url' => 'login')) }}.
The loop now, I have the impression (because there is no delay now), is gone, but I still get the same error:'Invalid credentials ', and of course, it does not log me in.
Code execution in routes.php(1-4, written by their execution order):
1.
Route::group(array('before' => 'auth'), function() {
Route::resource('cats', 'CatController');
Route::get('/', function() {
return Redirect::to('cats'); <<<<<<does not execute this line
});
});
2.
Route::post('login', function() {
if (Auth::attempt(Input::only('username', 'password'))) {
return Redirect::intended('/');
} else {
return Redirect::back() <<<<<< executes this line
->withInput()
->with('error', "Invalid credentials");
}
});
3.
Route::group(array('before' => 'auth'), function() {
Route::resource('cats', 'CatController');
Route::get('/', function() {
return Redirect::to('cats'); <<<<<does not execute this line
});
});
4.
Route::get('login', function() {
return View::make('login'); <<<<<< executes this line, which shows again the login page.
})
In route 2, the line if (Auth::attempt(Input::only('username', 'password'))) fails to log me in, and execution continues to return Redirect::back().
Well, in that case there is something wrong with your authentication. Are your users passwords hashed in database ?
Because Laravel attempt
method is hashing your password first and then comparing with records in database. So if you pass secret
as password and your row in database contains secret
in password column it won't work as at the end of the day the query will be SELECT WHERE password='hashedpassword'
.
I have entered the data in the database manually, so they 're not 'hashed'. I changed the password from '111111' to 'hashed111111'. I 'm entering, in the login screen, '111111'. Still does not work.
Edit: I guess I have misunderstood the meaning of 'hashed'.
I tried and with a 'hashed', still cannot login.
Yeah, you clearly did. The way Laravel protects user passwords is by hashing them. It means that it takes some password and creates a one-directional encrypted string from your password using BCrypt by default(I guess, I can be wrong here). So if you use Hash::make('string')
then you will get the string like $2y$10$34789f4374938g4vjvkldsjvlk4e
(by example, your hash will be different as the secret key in app/config/app.php
is used to make the hash unique per application). So when you are creating(registering) user when he is passing a password you use $user->password = Hash::make(Input::get('password'))
and save the user and you will get hashed password in database so no one can read it if your database will get stolen. Then try Auth::attempt()
like you did before and check if it works.
It doesn't work, now I 'm trying according to this page: http://code.tutsplus.com/tutorials/authentication-with-laravel-4--net-35593 But I get errors and with this one. I suppose it'll take me some ages before I make it work
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community