Last active
September 6, 2016 15:18
-
-
Save atoponce/09262d2c29122c5ff291d189adb1b11a to your computer and use it in GitHub Desktop.
Password generation in POSIX sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shuff() { | |
if [ $(command -v shuf) ]; then | |
shuf -n "$1" | |
elif [ $(command -v shuffle) ]; then | |
shuffle -f /dev/stdin -p "$1" | |
else | |
awk 'BEGIN{ | |
"od -tu4 -N4 -A n /dev/urandom" | getline | |
srand(0+$0) | |
} | |
{print rand()"\t"$0}' | sort -n | cut -f 2 | head -n "$1" | |
fi | |
} | |
gen_monkey_pass() { | |
I=0 | |
[ $(printf "$1" | grep -E '[0-9]+') ] && NUM="$1" || NUM="1" | |
until [ "$I" -eq "$NUM" ]; do | |
I=$((I+1)) | |
LC_CTYPE=C strings /dev/urandom | \ | |
grep -o '[a-hjkmnp-z2-9-]' | head -n 24 | paste -s -d \\0 /dev/stdin | |
done | column | |
} | |
gen_xkcd_pass() { | |
I=0 | |
[ $(printf "$1" | grep -E '[0-9]+') ] && NUM="$1" || NUM="1" | |
[ $(uname) = "SunOS" ] && FILE="/usr/dict/words" || FILE="/usr/share/dict/words" | |
DICT=$(LC_CTYPE=C grep -E '^[a-zA-Z]{3,6}$' "$FILE") | |
until [ "$I" -eq "$NUM" ]; do | |
I=$((I+1)) | |
printf "$DICT" | shuff 6 | paste -s -d '.' /dev/stdin | |
done | column | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment