summaryrefslogtreecommitdiff
path: root/misc/passwdgen
diff options
context:
space:
mode:
authorTimmy Keller <tjk@tjkeller.xyz>2021-09-11 00:36:13 -0500
committerTimmy Keller <tjk@tjkeller.xyz>2021-09-11 00:36:13 -0500
commit0a9053c2902adab8b94eaacdb15390441143078c (patch)
tree1f1a38272dbd554cde8cdec263187112b9c6a7e8 /misc/passwdgen
downloadscripts-0a9053c2902adab8b94eaacdb15390441143078c.tar.xz
scripts-0a9053c2902adab8b94eaacdb15390441143078c.zip
redid repo cus of fucking chromium rip old commit messages
Diffstat (limited to 'misc/passwdgen')
-rwxr-xr-xmisc/passwdgen16
1 files changed, 16 insertions, 0 deletions
diff --git a/misc/passwdgen b/misc/passwdgen
new file mode 100755
index 0000000..21dff29
--- /dev/null
+++ b/misc/passwdgen
@@ -0,0 +1,16 @@
+#!/bin/sh
+[ -n "`echo $1$2 | tr -d '[:digit:]'`" ] && echo "Usage: $0 [Length] [Itterations] [Set]" && exit
+[ -z "$1" ] && len=20 || len=$1
+[ -z "$2" ] && itt=5 || itt=$2
+[ -z "$3" ] && set='[:graph:]' || set=$3
+genpasswd() { tr -cd "$3" < /dev/urandom | fold -w$1 | head -n$2; }
+genpasswd $len $itt $set
+
+# Old solution using recursion which was much slower (and apparently less posix compliant) but also much cooler
+## This should all work in dash (its all posix compliant shell), but there are frequent segmentation faults and formatting errors in the output. Bash fixes that all for some reason. Probably an issue of recursion depth and some other bugs or something in dash I have no idea.
+#genpasswd() { pass=$pass`head -1 /dev/urandom | tr -cd '[:graph:]'` && [ `echo -n $pass | wc -m` -ge $len ] && echo $pass | cut -c -$len && pass="" || genpasswd; }
+#for i in `seq $itt`; do genpasswd; done
+
+# Other old solution that is much faster for extremely long passwords, but slower for many shorter ones since it utilizes a for loop
+#genpasswd() { tr -cd '[:graph:]' < /dev/urandom | head -c$1 && echo; }
+#for i in `seq $itt`; do genpasswd $len; done