Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hash::make('password') returning different results at every call

So,the title basically describes my problem. My Hash:make() is gone crazy. I've created a users table with a hashed password, but I can't get Laravel to accept my credentials and I think the problem is in the Hash::make.

So, test this code:

Route::get('/',  function()
{
    return Hash::make('1234');
});

every time I hit route '/' it gives me a different hash.

Does it behave like that for everyone? Any suggestions? I'm lost!

After Rocket tip, I've tried

    if(!Hash::check('1234', User::find(1)->password))
    return 'not';

$credentials = array(
        'email' => '[email protected]',
        'password' => '1234',
        //'remember' => $remember   
    );
if(Auth::attempt($credentials))
{
    return  View::make('hello');
}
return "Invalid Credentials";

But it keeps returning "Invalid Credentials". I've double checked my auth.php and it's setup correctly. Anything else I could try?

like image 217
Magus Avatar asked Jun 07 '13 15:06

Magus


1 Answers

That's what it's supposed to do. It's supposed to create a different password each time, as it's creating a new random salt.

To check the user's password, you use the check method.

if(Hash::check('1234', $password)){
}

Or you can use Auth::attempt.

$user = array(
    'email' => $email,
    'password' => $password
);
if (Auth::attempt($user)){
}

Docs: http://laravel.com/docs/security

like image 96
Rocket Hazmat Avatar answered Sep 30 '22 05:09

Rocket Hazmat