Skip to content

Instantly share code, notes, and snippets.

@pkutzner
Created March 14, 2016 22:44
Show Gist options
  • Save pkutzner/1bc69cef3daeaf1d1c09 to your computer and use it in GitHub Desktop.
Save pkutzner/1bc69cef3daeaf1d1c09 to your computer and use it in GitHub Desktop.
#!/bin/bash
# XKCD/diceware-style password generator that ensures at least one
# upper-case character is present and that each word has a
# minimum of 6 characters. Suitable for adding to your .aliases
# file.
dicepass() {
while true; do
local xpass=$(look . | grep -oE "^[A-Za-z]{6,}$" | shuf | head -4 | xargs)
if echo "$xpass" | grep -E "[A-Z]" >/dev/null 2>&1; then
echo "$xpass"
unset xpass
break
fi
done
}
# "Short word" (4-6 characters) XKCD/diceware-style password generator.
sdicepass() {
while true; do
local xpass=$(look . | grep -oE "^[A-Za-z]{4,6}$" | shuf | head -4 | xargs)
if echo "$xpass" | grep -E "[A-Z]" >/dev/null 2>&1; then
echo "$xpass"
unset xpass
break
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment