The default way to authenticate follows a field pattern e-mail and password (respectively on the table users
: email
and password
), as demonstrated on the link and on that other link.
The ideal and standard code would be this:
if (Auth::attempt(['email' => $email, 'password' => $password])) {
// Authentication passed...
return redirect()->intended('dashboard');
}
Outside this pattern is possible also as for example an instance of class User
:
$user = User::find(1);
if ($user) // encontrou o usuário
{
Auth::login($user); // autentica o usuário
}
do user search by bringing an instance of class User
and step in the method Auth::login($user)
and is also made the authentication.
In your specific case I could observe that you do not follow a pattern, so you should use the form of instance:
$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, the authentication of Larable follows a pattern from a table Users
and a class of eloquent User
, if there has been change in this should be careful to change in all parts so that your code does not break, ie it is possible to change the table and the model
for authentication, but this code should reflect in the settings of the Larable and that will depend on the version.
I made an answer, but, I also need to see how your class is
User
, you made changes, how is it? What is also the version of Laravel?– novic