diff --git a/extra/reset-password.js b/extra/reset-password.js index 3f6f79c1..2fbc622d 100644 --- a/extra/reset-password.js +++ b/extra/reset-password.js @@ -12,6 +12,10 @@ const rl = readline.createInterface({ }); const main = async () => { + if ("dry-run" in args) { + console.log("Dry run mode, no changes will be made."); + } + console.log("Connecting the database"); Database.initDataDir(args); await Database.connect(false, false, true); @@ -27,15 +31,26 @@ const main = async () => { console.log("Found user: " + user.username); while (true) { - let password = await question("New Password: "); - let confirmPassword = await question("Confirm New Password: "); + let password; + let confirmPassword; - if (password === confirmPassword) { - await User.resetPassword(user.id, password); + // When called with "--new-password" argument for unattended modification (e.g. npm run reset-password -- --new_password=secret) + if ("new-password" in args) { + console.log("Using password from argument"); + console.warn("\x1b[31m%s\x1b[0m", "Warning: the password might be stored, in plain text, in your shell's history"); + password = confirmPassword = args["new-password"] + ""; + } else { + password = await question("New Password: "); + confirmPassword = await question("Confirm New Password: "); + } - // Reset all sessions by reset jwt secret - await initJWTSecret(); + if (password === confirmPassword) { + if (!("dry-run" in args)) { + await User.resetPassword(user.id, password); + // Reset all sessions by reset jwt secret + await initJWTSecret(); + } break; } else { console.log("Passwords do not match, please try again.");