method Auth :: attempt laravel is not logging in

0

I'm trying to use the Auth :: attempt method to log in to my api, but it always falls on the else, even though it has the correspondence of that email / password in the database. Where can I configure this method Auth :: atempt? I think he should get the default parameter of laravel which is email / password, and how I switched to email / password does he not find?

My role:

    function login(Request $request){

        if (Auth::attempt(['email' => $request->email, 'senha' => $request->senha])){
            return 'Autenticado com sucesso';
        }else{
        return response()->json([
        'error' => 'Nome de usuário ou senha incorretos',
        'code' => 401,], 401);
    }
}

It always falls into the else ..

In my registry function, Hash :: make is used, does this impact Auth :: atempt in any way?

return User::create([
    'nome' => $data['nome'],
    'email' => $data['email'],
    'telefone' => $data['telefone'],
    'usuario_anjo' => $data['usuario_anjo'],
    'senha' => Hash::make($data['senha']),
]);       

@Edit:

I made a test by changing the hash :: make by bcrypty but still falls into the else ...

    
asked by anonymous 06.10.2018 / 16:46

2 answers

0

Instead of generating your password using Hash: make, try generating it using the bcrypt ($ data ['password']) function and see if it works. Using the laravel attempt method you can use the fields you want, not only by email / password.

    
09.10.2018 / 18:54
0

You can set an accessor in your App \ User.php .

/**
 * Get the password for the user.
 *
 * @return string
 */
public function getAuthPassword()
{
    return $this->senha;
}

This response was given based on the case below because they are similar.

link

    
15.10.2018 / 19:05