1459
This commit is contained in:
1 parent
4ab47a3e47
commit
ba016efbe8
21 files changed
+921
-72
No files matched your search
@@ -0,0 +1,35 @@
|
||||
// 用法: node scripts/hash-users.js
|
||||
// 生成哈希后的 users.json
|
||||
|
||||
const { createHash, randomBytes } = require("crypto");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
function hashPassword(password, salt) {
|
||||
return createHash("sha256").update(salt + password).digest("hex");
|
||||
}
|
||||
|
||||
// 在这里修改用户信息
|
||||
const users = [
|
||||
{ username: "admin", password: "admin123", name: "小赵", role: "admin" },
|
||||
{ username: "xiaomei", password: "xiaomei123", name: "小美", role: "user" },
|
||||
];
|
||||
|
||||
const hashedUsers = users.map(u => {
|
||||
const salt = randomBytes(16).toString("hex");
|
||||
const passwordHash = hashPassword(u.password, salt);
|
||||
return {
|
||||
username: u.username,
|
||||
passwordHash,
|
||||
salt,
|
||||
name: u.name,
|
||||
role: u.role,
|
||||
};
|
||||
});
|
||||
|
||||
const output = { users: hashedUsers };
|
||||
const outPath = path.join(__dirname, "..", "users.json");
|
||||
fs.writeFileSync(outPath, JSON.stringify(output, null, 2) + "\n");
|
||||
|
||||
console.log("已生成 users.json(密码已哈希)");
|
||||
console.log("用户名列表:", hashedUsers.map(u => u.username).join(", "));
|
||||
Reference in new issue
Block a user