I just cant seem to find a solution, my Auth::attempt()
function always return false and I cant find what I am doing wrong. This is my migration for tblusers:
public function up()
{
Schema::create('tblusers', function (Blueprint $table) {
$table->id();
$table->string('Username')->unique();
$table->string('FirstName');
$table->string('LastName');
$table->string('ContactNo')->unique();
$table->string('Email')->unique();
$table->timestamp('EmailVerifiedOn')->nullable();
$table->string('Password');
$table->integer('AddedBy');
$table->rememberToken();
$table->timestamps();
});
}
I customized the User
model:
class User extends Authenticatable
{
protected $table = 'tblusers';
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'Password', 'remember_token',
];
}
Therefore the password is no longer visible on User::
queries, so I use Auth::attempt
instead. This is how I insert my hashed password:
$password = $request->Password;
$hash = Hash::make($password);
$insertData = array(
...
'Email' => $email,
'Password' => $hash,
'AddedBy' => 0,
'created_at' => date('Y-m-d H:i:s')
);
This is how I use Auth::attempt
, can somebody point out what I'm doing wrong as it always returns false.
$credentials = array(
"Username" => $username,
"Password" => Hash::make($password)
);
return dd(Auth::attempt($credentials));
if (Auth::attempt($credentials)) {
$response = true;
} else {
$response = false;
}
question from:
https://stackoverflow.com/questions/65830306/laravel-7-auth-attempt-returns-false 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…