auth::Attempt method is not logging in

Asked

Viewed 415 times

-1

I’m trying to use the Auth::Attempt method to log in to my api, but it always falls into Else, even when it has in the database the correspondence of that email/password. Where can I set up this Auth::atempt method? I believe that it should take the default parameter of the Laravel which is email/password, and as I switched to email/password it does not find?

My job:

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

She always falls in Isis..

In my logging function Hash::make is used, it somehow impacts Auth::atempt?

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

@Edit:

I did a test replacing the Hash::make for bcrypty but still falls in LSE...

  • You changed the table because?

2 answers

-1

You can define a accessor in his App User.php.

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

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

https://stackoverflow.com/a/39382427/2116040

-1

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

Browser other questions tagged

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