php artisan make:filament-user bug
I want to create an account via the terminal by running the php artisan command make:filament-user. but when I try to log in, I can't. but after I changed the password via the database using bcrypt manually
8 Replies
Ok I think you might be double hashing it, try to remove the hashed cast
Then see how it saves
fixed
but not this
i deleted the
in User.php models
public function setPasswordAttribute($password)
{
$this->attributes['password'] = bcrypt($password);
}
public function setPasswordAttribute($password)
{
$this->attributes['password'] = bcrypt($password);
}
So that's a cast
Was it already there?
you should be checking if the password is already hashed when casting like that
yes
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Filament\Models\Contracts\FilamentUser;
use Filament\Panel;
use Filament\Models\Contracts\HasAvatar;
use Illuminate\Support\Facades\Storage;
use Spatie\Permission\Traits\HasRoles;
use BezhanSalleh\FilamentShield\Traits\HasPanelShield;
use TomatoPHP\FilamentDiscord\Traits\InteractsWithDiscord;
class User extends Authenticatable implements HasAvatar, FilamentUser
{
use HasApiTokens;
use HasRoles;
use HasPanelShield;
use HasFactory;
use Notifiable;
use InteractsWithDiscord;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $guarded = [
'id',
];
// protected $fillable = [
// 'name',
// 'no_hp',
// 'alamat',
// 'email',
// 'password',
// 'role',
// 'cabangs_id',
// 'bisnis_id',
// ];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
// public function setPasswordAttribute($password)
// {
// $this->attributes['password'] = bcrypt($password);
// }
// public function addres() : Morphone
// {
// return $this->morphone(related:addres::class,name:'addresable');
// }
public function getFilamentAvatarUrl(): ?string
{
return $this->avatar_url ? Storage::url("$this->avatar_url") : null;
}
public function bisnis()
{
return $this->belongsTo(Bisnis::class);
}
public function cabang()
{
return $this->belongsTo(Cabang::class, 'cabangs_id');
}
public function canAccessPanel(Panel $panel): bool
{
return $this->email && $this->password;
}
}
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Filament\Models\Contracts\FilamentUser;
use Filament\Panel;
use Filament\Models\Contracts\HasAvatar;
use Illuminate\Support\Facades\Storage;
use Spatie\Permission\Traits\HasRoles;
use BezhanSalleh\FilamentShield\Traits\HasPanelShield;
use TomatoPHP\FilamentDiscord\Traits\InteractsWithDiscord;
class User extends Authenticatable implements HasAvatar, FilamentUser
{
use HasApiTokens;
use HasRoles;
use HasPanelShield;
use HasFactory;
use Notifiable;
use InteractsWithDiscord;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $guarded = [
'id',
];
// protected $fillable = [
// 'name',
// 'no_hp',
// 'alamat',
// 'email',
// 'password',
// 'role',
// 'cabangs_id',
// 'bisnis_id',
// ];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
// public function setPasswordAttribute($password)
// {
// $this->attributes['password'] = bcrypt($password);
// }
// public function addres() : Morphone
// {
// return $this->morphone(related:addres::class,name:'addresable');
// }
public function getFilamentAvatarUrl(): ?string
{
return $this->avatar_url ? Storage::url("$this->avatar_url") : null;
}
public function bisnis()
{
return $this->belongsTo(Bisnis::class);
}
public function cabang()
{
return $this->belongsTo(Cabang::class, 'cabangs_id');
}
public function canAccessPanel(Panel $panel): bool
{
return $this->email && $this->password;
}
}
That'll be why then it was double hashing it.
idk why i have this code
// public function setPasswordAttribute($password)
// {
// $this->attributes['password'] = bcrypt($password);
// }
// public function setPasswordAttribute($password)
// {
// $this->attributes['password'] = bcrypt($password);
// }
Me neither.
anyway, thank you