]> git.cworth.org Git - empires-server/commitdiff
Add a utility lmno-passwd.py
authorCarl Worth <cworth@cworth.org>
Thu, 21 May 2020 14:11:53 +0000 (07:11 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 21 May 2020 15:43:04 +0000 (08:43 -0700)
This is a convenience to help the admin generate user entries for the
configuration that include correctly hashed passwords.

lmno-passwd.js [new file with mode: 0644]

diff --git a/lmno-passwd.js b/lmno-passwd.js
new file mode 100644 (file)
index 0000000..d756eac
--- /dev/null
@@ -0,0 +1,31 @@
+const bcrypt = require('bcrypt');
+
+/* The sigint:true property allows the user to abort the entire program
+ * with Control-C (rather than having to abort through each prompt).
+ */
+const prompt = require('prompt-sync')({
+  sigint: true
+});
+
+const username = prompt("Username: ");
+
+while (true) {
+  /* Use "echo:'*'" to avoid displaying the password while typing. */
+  var password = prompt("New password: ", {echo: '*'});
+  const password_again = prompt("Re-type new password: ", {echo: '*'});
+
+  if (password === password_again)
+    break;
+
+  console.log("Passwords do not match. Try again.");
+}
+
+const hash = bcrypt.hashSync(password, 12);
+
+console.log(`Add the following block to the 'users' object in lmno-config.js:
+
+    "${username}": {
+      "password_hash_bcrypt": "${hash}",
+      "role": "user"
+    }
+`);