1
Well I’m developing a login
own and in it I have others campos
and another tabela
, everything goes perfectly but always returns result false
.
I changed the file Authenticatable.php
inside \Illuminate\AuthZAuthenticatable
for :
public function getAuthPassword()
{
return $this->password; //anteriormente era assim
return $this->Senha;
}
In my file auth.php
inside config
is 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,
],
],
];
Man model Pessoa
is 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
did so:
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 cause the problem.
Thinking here I think it might be part of
senha
encrypted, I saved in the bank she 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.
Brother need the changes, for example my instance needs to be person, I can not have the user as main
– Renan Rodrigues
Brother just make a change to the folder
config/auth.php
in the key'providers' => [
 'users' => [
 'driver' => 'eloquent',
 'model' => App\Models\User::class,
 ],
put your class in the keymodel
.– novic
Ai utilizo su codigo ? Model User ?
– Renan Rodrigues
I did the editing, and you use the code I did or do your way, that method only needs an instance that in your case is
pessoa
.– novic
In the case of hash::check, it already does the password bycrypt itself ?
– Renan Rodrigues
Even the find part is working but the password is giving problem
– Renan Rodrigues
in the case bycrypt is a
helper
of the stabbingHash
, in the stab you have all the options.– novic
I don’t know how you saved the password you need maybe generate again. It happens a lot to confuse the password.
– novic
Yes, I’ll forehead here, just a moment
– Renan Rodrigues
I’m having trouble saving the password with bcrypt, how should I do it ? I know it’s another question :d
– Renan Rodrigues
takes an instance of the class
$p = Pessoa::find(1);
and then$p->Senha = bcrypt(123456);
and$p->save();
– novic
automatically by the model has as ?
– Renan Rodrigues
Make a method and run only to record once! then comment the line.
– novic
OK, just a lie
– Renan Rodrigues
Thanks, solved my problem, actually it was going wrong because I personally generated the hash, so I was not matching with what had in the database.
– Renan Rodrigues
Not at all @Renanrodrigues
– novic