改为通过环境变量初始化管理员密码
This commit is contained in:
+1
-1
@@ -5,4 +5,4 @@ DB_PORT=33306
|
|||||||
DB_NAME=aiameiba_com_new
|
DB_NAME=aiameiba_com_new
|
||||||
DB_USER=admin
|
DB_USER=admin
|
||||||
DB_PASSWORD=填入本地密码
|
DB_PASSWORD=填入本地密码
|
||||||
|
ADMIN_INITIAL_PASSWORD=首次部署时设置的管理员初始密码
|
||||||
|
|||||||
@@ -194,8 +194,12 @@ const seedAdminAndSettings = () => {
|
|||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const user = db.prepare('SELECT user_id FROM admin_users WHERE username = ?').get('admin');
|
const user = db.prepare('SELECT user_id FROM admin_users WHERE username = ?').get('admin');
|
||||||
if (!user) {
|
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 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(`
|
db.prepare(`
|
||||||
INSERT INTO admin_users (user_id, username, password_hash)
|
INSERT INTO admin_users (user_id, username, password_hash)
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
|
|||||||
Reference in New Issue
Block a user