The default way to do authentication follows a email and password users
: email
and password
), as demonstrated link and this other link .
The ideal and default code would be :
if (Auth::attempt(['email' => $email, 'password' => $password])) {
// Authentication passed...
return redirect()->intended('dashboard');
}
Outside of this pattern you can also an instance of class in> User
:
$user = User::find(1);
if ($user) // encontrou o usuário
{
Auth::login($user); // autentica o usuário
}
Do the user search by bringing an instance of class User
and step in method Auth::login($user)
and also / em> .
In your specific case I noticed that it does not follow a pattern, so you should use the instance form:
$prontuario = Input::get('prontuario');
$senha = Input::get('senhas');
$user = User::where('prontuario', $prontuario)
->first(); // buscando um registro desse pontuário
if ($user) // encontrou o usuário
{
if (Hash::check($senha, $user->senha)) // conferindo senha
{
Auth::login($user); // autentica o usuário
}
else
{
//senha inválida...
}
}
else
{
return Redirect::to('/')->withErrors('Prontuario ou senha inválidos!');
}
There is also a factor, laravel follows a pattern from a Users
table and a class from eloquent User
, if there was a change in this you should take care to change everywhere so your code does not break, ie it is possible to change the table and model
for authentication, but this code should reflect in the settings of the laravel and this will depend on the version.