phphashlaravel-4mcrypteloquent

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@example.com',
        '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?


Solution

  • 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