Auth always returning false

1

Well I'm developing a login itself and I have other campos and another tabela , everything goes perfectly but always returns false result.

I changed the file Authenticatable.php within \Illuminate\AuthZAuthenticatable to:

public function getAuthPassword()
{
   return $this->password; //anteriormente era assim
    return $this->Senha;
}

In my file auth.php within config it looks like this:

return [

'defaults' => [
    'guard' => 'web',
    'passwords' => 'pessoas',
],

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'pessoas',
    ],

    'api' => [
        'driver' => 'token',
        'provider' => 'pessoas',
    ],
],

'providers' => [
    'pessoas' => [
        'driver' => 'eloquent',
        'model' => App\Pessoa::class,
    ],

     'pessoas' => [
         'driver' => 'database',
         'table' => 'pessoas',
     ],
],


'passwords' => [
    'pessoas' => [
        'provider' => 'pessoas',
        'email' => 'auth.emails.password',
        'table' => 'password_resets',
        'expire' => 60,
    ],
  ],
];

My model Pessoa looks like this:

use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;

class Pessoa extends Authenticatable
{
   use SoftDeletes;
   protected $fillable = [
    'NmPessoa',
    'CPF',
    'Email',
    'Senha',
    'Telefone',
    'DtNasc',
    'Sexo',
    'FglNewsLater',
    'FglStPessoa',
    'ObsPessoa',
    'FglADM',
    'FglCliente',
    'FglFuncionario',
    'Cidade',
    'Estado',
    'Bairro',
    'Rua',
    'Num',
    'Complemento',
    'CEP'
  ];

   protected $hidden = [
     'Senha', 'remember_token',
   ];

   protected $primaryKey = 'CdPessoa';
   protected $dates = ['deleted_at'];

  public function setPasswordAttribute($Senha)
  {
    $this->attributes['Senha'] = bcrypt($Senha);
  }
}

In my controller AuthController I did like this:

use Auth;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

class AuthController extends Controller
{

  public function authenticate(Request $request)
  {
    $email = $request->input('email');
    $password = $request->input('senha');


    dd(Auth::attempt(['Email' => $email, 'Senha' => $password]));

    if (Auth::attempt(['Email' => $email, 'Senha' => $password])) {
        // Authentication passed...
        return redirect()->intended('/');
    }
 }
}

And in my HTML:

<form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }}">
     {{ csrf_field() }}
    <div class="form-group">
       <input type="email" name="email" lass="form-control" id="email-modal" placeholder="E-mail">
    </div>
    <div class="form-group">
         <input type="password" name="senha" class="form-control" id="password-modal" placeholder="Senha">
    </div>
    <p class="text-center">
       <button type="submit" class="btn btn-primary"><i class="fa fa-sign-in"></i> Entrar</button>
    </p>
 </form>

With all this, what could be the cause of the problem.

  

Thinking here I think it could be the part of senha encrypted, I saved in the database it bcrypt (Password), already tried to change this part the attempt () but it did not work and continued giving false. Remember that I have the user in the database.

    
asked by anonymous 13.10.2016 / 01:23

1 answer

2

You do not need to change the code that comes with , because it has many different ways of implementing user , return what was before and follow this logic.

First thing in the folder login file config and has an array auth.php put providers its model Person.

'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => Pessoa::class,
        ],

Create a instance of class classe , and search by, User , or any field (or fields) you want and at the end of the expression use email . If the result was favorable and you brought a instance from class first() , use the instance of the class User ( User ) Authenticate A User Instance that the authentication of the user is effected, being very similar to the \Auth::login($find); command, different, because the responsibility of checking the data is the responsibility of the developer.

Simple Example:

$user = new \App\Models\Pessoa();
$find = $user->where('Email', '[email protected]')->first();

if ($find) // se encontrou o usuário
{
    //verifiando a senha texto enviado pelo form
    //comparando com hash gravado no banco
    if (\Hash::check($request->input('senha'), $find->Senha)) 
    {
        //autorizando o login do usuário.
        \Auth::login($find);
    }
}

return redirect('/home');

Link demonstrates the other means of authentication:

Other Authentication Methods - Other Authentication Methods

  • \Auth::attempt - For instance of class Authenticate A User Instance .
  • User - By the primary key configured in class Authenticate A User By ID .
  • User - Authentication per request ( this is not what you need ).
13.10.2016 / 02:48