Modification : remorque. vers Grésille & ra. vers Kimsufi.
[lhc/ateliers.git] / local / htpasswd-add
diff --git a/local/htpasswd-add b/local/htpasswd-add
new file mode 100755 (executable)
index 0000000..0438e0a
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh -eu
+# SYNTAX: $user <$password
+tool=$(readlink -e "${0%/*}/..")
+. "$tool"/local/lib.sh
+
+user=$1
+stty -echo
+IFS= read -r password
+stty echo
+salt="$(openssl rand -base64 3)"
+sha1=$(
+       cat <<-EOF | base64
+               $(openssl dgst -binary -sha1 <<-EOF
+                       $password$salt
+                       EOF
+                )$salt
+               EOF
+       )
+cat <<-EOF
+       $user:{SSHA}$sha1
+       EOF