From bc304d9bfae092ce4521e3d5aadd0bfdeaaecfcc Mon Sep 17 00:00:00 2001 From: baldo Date: Mon, 11 Jul 2022 13:24:15 +0200 Subject: [PATCH] Added script to generate password hashes. --- README.md | 2 +- bin/bcrypt.js | 24 ++++++++++++++++++++++++ bin/mkpasswd.sh | 23 +++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100755 bin/bcrypt.js create mode 100755 bin/mkpasswd.sh diff --git a/README.md b/README.md index 1b58bd7..b82a0cf 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ Dann die `config.json` anpassen nach belieben. Es gibt die folgenden Konfigurati * **`server.internal.active`** Gibt an, ob interne URLs, wie Admin-Panel und Logging-Interface, erreichbar sein sollen, z. B.: `true` * **`server.internal.users`** Liste an Nutzer*innen im folgenden Format. Der Passwort-Hash kann mit dem Befehl - `mkpasswd -m bcrypt` generiert werden. + `mkpasswd -m bcrypt -R 10` oder dem beiliegenden Skript `bin/mkpasswd.sh` generiert werden. ``` { diff --git a/bin/bcrypt.js b/bin/bcrypt.js new file mode 100755 index 0000000..91f342e --- /dev/null +++ b/bin/bcrypt.js @@ -0,0 +1,24 @@ +#!/usr/bin/env node + +const bcrypt = require('bcrypt'); +const saltRounds = 10; + +const stdout = process.stdout +const stdin = process.stdin + +let password = ''; + +stdin.on('readable', () => { + let chunk; + while ((chunk = stdin.read()) !== null) { + password += chunk; + } +}); + +process.stdin.on('end', () => { + if (password[password.length - 1] === '\n') { + password = password.substring(0, password.length - 1); + } + const hash = bcrypt.hashSync(password, saltRounds); + stdout.write(`${hash}\n`); +}); diff --git a/bin/mkpasswd.sh b/bin/mkpasswd.sh new file mode 100755 index 0000000..1a58bf1 --- /dev/null +++ b/bin/mkpasswd.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "${BASH_SOURCE[0]}")" + +while :; do + read -sp "Password: " password + echo + + read -sp "Confirm: " confirmation + echo + + if [[ "$password" == "$confirmation" ]]; then + break + fi + + echo + echo "Passwords do not match, try again." + echo +done + +exec node ./bcrypt.js <<<"$password"