改为通过环境变量初始化管理员密码

This commit is contained in:
amb
2026-09-09 18:40:18 +08:00
parent 06c8231425
commit 08b79588ff
2 changed files with 6 additions and 2 deletions
+1 -1
View File
@@ -5,4 +5,4 @@ DB_PORT=33306
DB_NAME=aiameiba_com_new
DB_USER=admin
DB_PASSWORD=填入本地密码
ADMIN_INITIAL_PASSWORD=首次部署时设置的管理员初始密码
+5 -1
View File
@@ -194,8 +194,12 @@ const seedAdminAndSettings = () => {
const crypto = require('crypto');
const user = db.prepare('SELECT user_id FROM admin_users WHERE username = ?').get('admin');
if (!user) {
const initialAdminPassword = process.env.ADMIN_INITIAL_PASSWORD;
if (!initialAdminPassword) {
throw new Error('首次初始化管理员账号需要配置 ADMIN_INITIAL_PASSWORD');
}
const salt = crypto.randomBytes(16).toString('hex');
const hash = crypto.scryptSync('已移除的历史密码', salt, 64).toString('hex');
const hash = crypto.scryptSync(initialAdminPassword, salt, 64).toString('hex');
db.prepare(`
INSERT INTO admin_users (user_id, username, password_hash)
VALUES (?, ?, ?)