I'm getting problem with manually logging in users using Auth::loginUsingId
. Before I do that I need to check if password matches and there is my problem. Password comparision is always returning false;
That's how I save password to DB:
$user = User::create([
'password' => Hash::make(Input::get('password')),
]);
And that's how I try to compare these two passwords
$u = User::where('username', $username)->first();
$password = Hash::make(Input::get('password'));
var_dump($u->password == $password);
And this is returning false, and I don't know where the problem is.
EDIT: In DB field varchar is 70 char long, hash is 60 characters long
Ok I've noticed: that every time Hash::make gives another string from my password. How it's even possible? I mean how then Auth::attempt
works?
Manually Logging In A User If you need to log an existing user instance into your application, you may call the login method with the user instance: Auth::login($user); This is equivalent to logging in a user via credentials using the attempt method.
From Laravel 5 onward, you can use the bcrypt() function to hash a plaintext. So, you can save that hashed password in DB and then, compare the hashed password again to match. $save_password = bcrypt('plain_text_password'); $check_password = bcrypt('provided_password_while_login_request'); And then, compare these two.
Try the following:
$user = User::where('username', $username)->first();
if (Hash::check(Input::get('password'), $user->password))
{
// The passwords match...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With