Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel Hash::make keep giving a different results

I'm trying to implement authentication in laravel 4

When the user registers, I hash the password and save it, like this:

$password = Hash::make(Input::get('password'));

Then when the user tries to login, I want to authenticate him/her with the following code:

if (Auth::attempt(array('username' => Input::get('username'), 'password' => Hash::make(Input::get('password')))))
{
    return Redirect::intended('dashboard');
}

and that never succeeds. I tried to debug the code and it seems that the Hash::make function always gives a different result.

Am I using a good authentication methods?

like image 751
Anastasie Laurent Avatar asked Sep 01 '25 16:09

Anastasie Laurent


2 Answers

Don't Hash the password you are giving to the Auth::attempt method, it should be like this:

Auth::attempt(array('username' => Input::get('username'), 'password' => Input::get('password')));

You may also check the password using Hash::check('password', $hashedPassword). Read more about security on Laravel website.

like image 185
The Alpha Avatar answered Sep 04 '25 07:09

The Alpha


Do not hash the password in the auth::attempt() function the code should be like this:

Auth::attempt(array('username' => Input::get('username'), 'password' => Input::get('password')));

The auth::attempt() will hash the password and then check if it matches the one stored in the database

like image 42
Mohamed Bouallegue Avatar answered Sep 04 '25 08:09

Mohamed Bouallegue