// Generate an ADMIN_PASS_HASH for .env from a password. // // node scripts/set-password.js "my super secret" // node scripts/set-password.js # prompts (hidden input) // // Paste the printed line into .env — the plaintext password is never stored. import readline from "node:readline"; import { hashPassword } from "../lib/auth.js"; function ask(question) { return new Promise((resolve) => { const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); // hide typed characters const orig = rl._writeToOutput.bind(rl); rl._writeToOutput = (str) => { if (str.includes(question)) orig(str); else orig("*"); }; rl.question(question, (answer) => { rl.close(); process.stdout.write("\n"); resolve(answer); }); }); } const argPw = process.argv.slice(2).join(" ").trim(); const pw = argPw || (await ask("New admin password: ")); if (!pw || pw.length < 8) { console.error("Password must be at least 8 characters."); process.exit(1); } console.log("\nAdd this line to your .env:\n"); console.log(`ADMIN_PASS_HASH=${hashPassword(pw)}\n`);