Customized authentication with CPF and E-MAIL

Asked

Viewed 878 times

6

I’m thinking of a way to authenticate users using the email and the CPF of the same, so far not found a way to do, someone has a suggestion?

public function auth(Request $request) {
    $credenciais = $request->only('cli_email', 'cli_cpf');
}

1 answer

5


The Laravel Framework, has a form of authentication with the instance of class User, it is then possible to check other relevant data for access to the system, following example:

$user = User::where('cpf', $cpf)->where('email', $email)->first();
if ($user) // se verdade existe um usuário com essas informações
{
    Auth::login($user); //efetuando a operação de autenticação
}

but, would not be a security breach?, because, it is easy to discover the CPF and the E-mail of some user, the password should also be informed by being a data of each user.

  • I agree with you when you say that it is a security breach, but unfortunately the client needs this type of login, I left the same well informed about the situation, thank you very much for the reply, had already finished the job, but even so I still consider as a response.

  • No problem @geekcom, it was a warning, and client is client does not always understand our work ... !!!

  • And if I have to email or cpf along with the password?

  • 1

    @Erloncharles is the same logic only to group the where and pass the two parameters, because it only needs the instance to log in. That is to say https://laravel.com/docs/5.6/queries#Parameter-grouping

Browser other questions tagged

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