Dennys
3 weeks ago
131
2
Laravel

"These credentials do not match our records" in Laravel 5.8 auth login page

Posted 3 weeks ago by Dennys

Hello,

after restoring my laravel project backup I can't login anymore, the authentication used to work well, I can't understand which is the problem.

I configured the .env file to work with the database and the migration works, so the database connection shouldn't be the problem.

It's a multi-table authentication with two different login page.

This is my web.php with the routes:

<?php
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    return view('welcome');
});

Auth::routes([
    'register' => false,
    'verify' => false,
    'reset' => false
]);

Route::group(['prefix' => 'formatore',  'middleware' => 'auth:formatore'],function (){
    Route::get('/login', 'Auth\[email protected]')->name('formatore.login');
    Route::post('/login', 'Auth\[email protected]')->name('formatore.login.submit');
    Route::get('/', '[email protected]')->name('formatore.dashboard');
});

Route::group(['prefix' => 'home',  'middleware' => 'auth:web'],function (){
    Route::get('/', '[email protected]')->name('utente.dashboard');
});

The auth.php in the config folder:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Authentication Defaults
    |--------------------------------------------------------------------------
    */

    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],

    /*
    |--------------------------------------------------------------------------
    | Authentication Guards
    |--------------------------------------------------------------------------
    */

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
            'hash' => false,
        ],

        'formatore' => [
            'driver' => 'session',
            'provider' => 'formatori',
        ],

        'formatore-api' => [
            'driver' => 'token',
            'provider' => 'formatori',
            'hash' => false,
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | User Providers
    |--------------------------------------------------------------------------
    */

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ],

        'formatori' => [
            'driver' => 'eloquent',
            'model' => App\Formatore::class,
        ],
    ],
];

The LoginController:

<?php

namespace App\Http\Controllers\Auth;

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

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    */

    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');
    }
}

The FormatoreLoginController:

<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;

class FormatoreLoginController extends Controller
{

    public function __construct()
    {
        $this->middleware('guest:formatore');
    }

    public function showLoginForm()
    {
        return view('auth.formatore-login');
    }

    public function login(Request $request)
    {
        $remember = $request->remember;

        $this->validate($request, [
            'email' => 'required|email',
            'password' => 'required|min:6'
        ]);

        if (Auth::guard('formatore')->attempt(['email' => $request->email, 'password' => $request->password], $remember)) {
            return redirect()->intended(route('formatore.dashboard'));
        }

        return redirect()->back()->withInput($request->only('email', 'remember'));
    }
}

These are the pages that I find useful, I deleted the part of code that i find useless.

Thank you very much for the help, it's appreciated.

Please sign in or create an account to participate in this conversation.