add password generate tool

php artisan password:generate admin
This commit is contained in:
Jethro Lin 2024-11-17 15:03:38 +08:00
parent 7343f5d598
commit 9269674739
2 changed files with 68 additions and 0 deletions

View file

@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
class GeneratePassword extends Command
{
protected $signature = 'password:generate {account}';
protected $description = 'Generate a password for a user and output the update SQL';
public function handle(): void
{
$account = $this->argument('account');
$password = Str::random(12); // 生成12位随机密码
$hashedPassword = Hash::make($password);
$this->info('Generated password for account: ' . $account);
$this->info('Plain password: ' . $password);
$this->info('Hashed password: ' . $hashedPassword);
// 生成 SQL
$sql = sprintf(
"UPDATE users SET password = '%s' WHERE account = '%s';",
$hashedPassword,
$account
);
$this->newLine();
$this->info('SQL to update password:');
$this->line($sql);
}
}

31
clean.sh Normal file
View file

@ -0,0 +1,31 @@
#!/bin/bash
# 確保腳本執行失敗時中止
set -e
echo "開始清除 Laravel 所有快取..."
# 清除配置快取
echo "清除配置快取..."
php artisan config:clear
# 清除路由快取
echo "清除路由快取..."
php artisan route:clear
# 清除視圖快取
echo "清除視圖快取..."
php artisan view:clear
# 清除應用快取
echo "清除應用快取..."
php artisan cache:clear
# 如果需要重新生成快取,可以啟用以下命令
# echo "重新生成配置快取..."
# php artisan config:cache
# echo "重新生成路由快取..."
# php artisan route:cache
echo "Laravel 快取清除完成!"