Răsfoiți Sursa

Simple api key generator

Stuart H Jimenez 11 ani în urmă
părinte
comite
95b77d8bff
1 a modificat fișierele cu 37 adăugiri și 0 ștergeri
  1. 37 0
      bin/v-generate-api-key

+ 37 - 0
bin/v-generate-api-key

@@ -0,0 +1,37 @@
+#!/bin/bash
+# info: generate api key
+# options: none
+#
+# The function creates a key file in /usr/local/vesta/data/keys/
+
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+keygen()
+{
+    cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n 1
+}
+KEYS='/usr/local/vesta/data/keys/'
+HASH=$(keygen)
+
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+if [[ -e ${KEYS}${HASH} ]] ; then
+    while [[ -e ${KEYS}${HASH} ]] ; do
+        HASH=$(keygen)
+    done
+fi
+
+touch ${KEYS}${HASH}
+echo ${HASH}
+
+#----------------------------------------------------------#
+#                       Vesta                              #
+#----------------------------------------------------------#
+
+exit