Laravel 5.2: Multi authentication always returns false

Asked

Viewed 89 times

0

Is always returning error when making the login, even if the data is correct. I’ve seen several topics about this error, but none solved the problem.

CONTROLLER

public function cadastro(Request $request)
{
    $dataForm = $request->all();

    $dataForm['password'] = bcrypt($dataForm['password']);

    $cliente = $this->cliente->create($dataForm);
}

public function login(Request $request)
{
    $credentials = ['email' => $request->email, 'password' => $request->password];

    if(Auth::guard('cliente')->attempt($credentials)) {
        echo 'OK';
    } else {
        echo 'ERRO';
    }
}

MODEL

class Cliente extends Authenticatable
{
    protected $table = 'clientes';
    protected $dates = ['created_at','updated_at'];
    protected $fillable = ['nome', 'sobrenome', 'email', 'password'];
    protected $hidden = ['password'];
}

AUTH

return [

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

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

        'cliente' => [
            'driver' => 'session',
            'provider' => 'clientes',
        ],

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

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

        'clientes' => [
            'driver' => 'eloquent',
            'model' => App\Cliente::class,
        ],
    ],
];

I’m creating the table without Migration, that is, right in the bank:

CREATE TABLE clientes(id int auto_increment, 
                     nome varchar(50), 
                     sobrenome varchar(50), 
                     email varchar(50), 
                     password varchar(50), 
                     created_at datetime, 
                     updated_at datetime, 
                     primary key(id));
  • Which error is returning?

  • Does not return any error, is that it always falls on Else at the time of authenticating. As if I had typed the wrong data.

  • I already put something similar: take a look at this link answer: https://answall.com/questions/162965/laravel-authatempt-sempre-retorna-false/162970#162970

  • Another example: https://answall.com/questions/158409/auth-returning-sempre-false/158424#158424 must be in the settings problems entering the else

  • I checked the examples, but it remains the same thing. Authentication in the table users works normal, the problem is this other table clients.

  • Already tried to change password again and redo login?

  • Yes, the same thing happens. The email he finds in the bank, the problem is to compare the password typed with the one in the bank.

  • Dude, I decided to change the size of the password field in the bank. I had put 50, and it seems that it is small for the bcrypt, I switched to 100 and now is comparing just right. Thanks for the help

  • Put as answer explaining the reason and the solution.

Show 4 more comments

1 answer

0

The bcrypt occupies more than 50 characters, so I changed the size in the database to 100 and the problem was solved!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.