首次发布git
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
const { scrypt, randomBytes } = require('crypto');
|
||||
const { promisify } = require('util');
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
const scryptAsync = promisify(scrypt);
|
||||
|
||||
async function hashPassword(password) {
|
||||
const salt = randomBytes(16).toString("hex");
|
||||
const derivedKey = await scryptAsync(password, salt, 64);
|
||||
return `${salt}:${derivedKey.toString("hex")}`;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log("Resetting password to 'admin'...");
|
||||
const hashedPassword = await hashPassword("admin");
|
||||
const settings = await prisma.globalSettings.findFirst();
|
||||
|
||||
if (settings) {
|
||||
await prisma.globalSettings.update({
|
||||
where: { id: settings.id },
|
||||
data: { password: hashedPassword }
|
||||
});
|
||||
console.log("Password reset successfully.");
|
||||
} else {
|
||||
await prisma.globalSettings.create({
|
||||
data: {
|
||||
id: "default",
|
||||
password: hashedPassword,
|
||||
},
|
||||
});
|
||||
console.log("Settings created with default password.");
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
.catch(e => console.error(e))
|
||||
.finally(async () => await prisma.$disconnect());
|
||||
Reference in New Issue
Block a user