aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-01-22 02:21:30 +0100
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-02-28 01:43:59 +0100
commit08a38aea94f3247fe1334db46b45d74ebaeef892 (patch)
tree0ef91165c7ce9a86222f9945af48617d91bcb28a
parent1b990951f550f042466799325f2c5bd260893ac5 (diff)
downloadslcl-08a38aea94f3247fe1334db46b45d74ebaeef892.tar.gz
Add usergen
This script takes a username and password from standard input and generates a JSON object that can be appended to the "users" object in db.json.
-rwxr-xr-xusergen29
1 files changed, 29 insertions, 0 deletions
diff --git a/usergen b/usergen
new file mode 100755
index 0000000..875ef20
--- /dev/null
+++ b/usergen
@@ -0,0 +1,29 @@
+#! /bin/sh
+
+echo Username: >&2
+read -r USER
+echo Password: >&2
+read -r PWD
+
+PWD=$(printf '%s' $PWD | xxd -p | tr -d '\n')
+SALT=$(openssl rand 32 | xxd -p | tr -d '\n')
+KEY=$(openssl rand 32 | xxd -p | tr -d '\n')
+PWD=$(printf '%s%s' $SALT $PWD)
+
+ROUNDS=1000
+
+for i in $(seq $ROUNDS)
+do
+ printf "\r%d/$ROUNDS" $i >&2
+ PWD=$(printf '%s' $PWD | xxd -p -r | sha256sum | cut -d' ' -f1)
+done
+
+echo >&2
+cat <<-EOF
+{
+ "name": "$USER",
+ "password": "$PWD",
+ "salt": "$SALT",
+ "key": "$KEY"
+}
+EOF