Support the ongoing development of Laravel.io →
posted 10 years ago
Authentication
Last updated 2 years ago.
0

You're doing the following:

  1. Fetching a user from the database
  2. Assigning their username and hashed password to variables
  3. Attempting to log the user in using their hashed password

However that won't work because...

attempt takes a username (eg: admin) and a plain text password (eg: 123). The user database stores the hashed password (eg: $2a$10$xbFFpiHRRv8y6e.6STPQxehcLwY8V9Lq/HUNjfbuCdHSe2PTLBcNy) which means you're passing the hashed password to attempt, which will always fail.

If you want to login a user by their ID (eg: 1) use loginUsingId:

Auth::loginUsingId(1);

If you want to login a user using a provided username and password use attempt, eg:

$username = 'admin';
$password = '123';
Auth::attempt(['username' => $username, 'password' => $password]);

http://laravel.com/docs/security#authenticating-users

Last updated 2 years ago.
0

Many thanks for your help!

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Faydaen faydaen Joined 21 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.