67 lines
2.0 KiB
PHP
67 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\UserDosen;
|
|
use App\Models\UserStaff;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class HashExistingPasswords extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'app:hash-passwords';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Hash all existing plain text passwords in users_dosen and users_staff tables';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle()
|
|
{
|
|
$this->info('Starting password hashing process...');
|
|
|
|
// Hash UserDosen passwords
|
|
$dosenCount = 0;
|
|
UserDosen::whereNotNull('password')
|
|
->whereRaw("password NOT LIKE '$2y$%'")
|
|
->whereRaw("password NOT LIKE '$2a$%'")
|
|
->whereRaw("password NOT LIKE '$2b$%'")
|
|
->chunk(100, function ($users) use (&$dosenCount) {
|
|
foreach ($users as $user) {
|
|
$user->update(['password' => Hash::make($user->password)]);
|
|
$dosenCount++;
|
|
}
|
|
});
|
|
|
|
$this->info("✓ Hashed {$dosenCount} Dosen passwords");
|
|
|
|
// Hash UserStaff passwords
|
|
$staffCount = 0;
|
|
UserStaff::whereNotNull('password')
|
|
->whereRaw("password NOT LIKE '$2y$%'")
|
|
->whereRaw("password NOT LIKE '$2a$%'")
|
|
->whereRaw("password NOT LIKE '$2b$%'")
|
|
->chunk(100, function ($users) use (&$staffCount) {
|
|
foreach ($users as $user) {
|
|
$user->update(['password' => Hash::make($user->password)]);
|
|
$staffCount++;
|
|
}
|
|
});
|
|
|
|
$this->info("✓ Hashed {$staffCount} Staff passwords");
|
|
|
|
$this->info('Password hashing completed successfully!');
|
|
$this->info("Total: {$dosenCount} Dosen + {$staffCount} Staff = " . ($dosenCount + $staffCount) . ' passwords hashed');
|
|
}
|
|
}
|