1

I am attempting to log in using Laravel however I am having some issues

This is how i save my user:

$user = User::create(array('email'=> $_REQUEST['email'], 'password' => encrypt($password), 'firstname'=> $_REQUEST['firstname'], 'lastname'=>$_REQUEST['lastname'], 'unecrypted'=> $password));

Now as you can see i use encrypt($password) this created the following record in my database:

'39', '[email protected]', 'eyJpdiI6Iis5RTRQdjBCV1piSVEwN0ZwRDQxa1E9PSIsInZhbHVlIjoiTnY1UnJ0YkVqZkY0VlhzdWhBK1QzUWxIdTc0SXNBRHlPcHQrcXpicmZHND0iLCJtYWMiOiJhODM2ZDI4ZTE5ZjY5YjlkNmQyOGIyYTdiOTU3NzFkNmNmZWNlOGVhMDNjYjY0ZTFiZjZiOGJlNWM3N2U4MmViIn0=', '2018-01-01 13:45:51', '2018-01-01 13:45:51', NULL, 'Marc', 'Rasmussen'

Which looks correct.

Then i have the following LoginController:

    namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }
}

However, when I attempt to login with my password (which I know is correct) I get the following message:

These credentials do not match our records.

Can anyone see what I've done wrong?

1
  • You shouldn't use "encrypt" for passwords, you should make a password hash laravel.com/docs/5.5/hashing Commented Jan 1, 2018 at 13:53

2 Answers 2

4

Use the bcrypt() helper to encrypt a password:

'password' => bcrypt($password),
Sign up to request clarification or add additional context in comments.

5 Comments

I'm not too familiar with Laravel, but isn't it preferred to use the Hash facade? laravel.com/docs/5.5/hashing
@JimL Laravel uses bcrypt() by default to encrypt passwords. bcrypt() is just a shourtcut for Hash::make().
Yes but when they change their mind and update to use a new hash algo then I assume the Hash facade will offer the same portability as the standard password lib.
@JimL they can also remove facade or rename the make method to something else etc. So, I wouldn't worry about that at all. )
True, it would mean they do something seriously wrong with the apis and interfaces they give laravel developers, but don't we all ^^ Sorry for dragging out the discussion, just a fan of latching on to abstractions/interfaces in tools I use as I expect them to survive - at least for quite a while :)
0

If you want to use your own password encryption method you do not use laravel's built in Auth functionality Becuase laravel Auth match password only while the password encrypted through bcrypt method, like bcrypt($password);

If you want to use you own encryption method you need to overwrite Auth login functionality and make own login logic. I hope you understand what i want to say is. Thank you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.