Seed users with and without 2FA enabled

This commit is contained in:
Arya Dwi Putra
2025-12-02 10:09:07 +07:00
parent 01a0348c74
commit 7b178790fd
2 changed files with 44 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
<?php
namespace Database\Seeders;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
class TwoFactorUserSeeder extends Seeder
{
public function run(): void
{
// User tanpa 2FA (viewer)
$viewer = User::firstOrCreate(
['email' => 'viewer@example.com'],
[
'name' => 'Viewer Default',
'password' => Hash::make('password123'),
]
);
// User dengan 2FA aktif
$twoFaUser = User::firstOrCreate(
['email' => 'secure@example.com'],
[
'name' => '2FA User',
'password' => Hash::make('password123'),
]
);
$twoFaUser->forceFill([
'two_factor_secret' => 'JBSWY3DPEHPK3PXP', // contoh secret base32
'two_factor_recovery_codes' => [
'RCVR-1234-ABCD',
'RCVR-5678-EFGH',
'RCVR-9012-IJKL',
'RCVR-3456-MNOP',
],
'two_factor_enabled' => true,
'two_factor_confirmed_at' => now(),
])->save();
}
}