From 92696747394db5febbead0ad1b6ab75334ae5b84 Mon Sep 17 00:00:00 2001 From: Jethro Lin Date: Sun, 17 Nov 2024 15:03:38 +0800 Subject: [PATCH] add password generate tool php artisan password:generate admin --- app/Console/Commands/GeneratePassword.php | 37 +++++++++++++++++++++++ clean.sh | 31 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 app/Console/Commands/GeneratePassword.php create mode 100644 clean.sh diff --git a/app/Console/Commands/GeneratePassword.php b/app/Console/Commands/GeneratePassword.php new file mode 100644 index 0000000..6ee004b --- /dev/null +++ b/app/Console/Commands/GeneratePassword.php @@ -0,0 +1,37 @@ +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); + } +} \ No newline at end of file diff --git a/clean.sh b/clean.sh new file mode 100644 index 0000000..854b11a --- /dev/null +++ b/clean.sh @@ -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 快取清除完成!"