First example immediately reminded me of:
head -c 8 /dev/random | base64
I'm not a fan of doing everything through bash, but reaching for python just to get some random characters seems particularly bad.
head -c 8 /dev/random | base64
I'm not a fan of doing everything through bash, but reaching for python just to get some random characters seems particularly bad.
######################################
# Generate a random password from /dev/urandom
# pw [length [num_passwords [characters]]
# Arguments:
# $1 => The length of password
# $2 => The number of passwords to generate
# $3 => The acceptable character set, PCRE regex
######################################
function pw {
if [[ "x$1" == "x-h" ]]; then
echo "Usage: pw [length:20 [num_passwords:1 [character_set:a-zA-Z0-9._!@#$%^&*()]]]"
else
LC_CTYPE=C \
tr -dc "${3:-'a-zA-Z0-9._!@#$%^&*()'}" < /dev/urandom \
| fold -w "${1:-20}" \
| head -n "${2:-1}"
fi
# There's always `openssl rand -base64 12` for simplicity
} password = os.popen("head -c 8 /dev/random | base64").read()> head -c 8 /dev/random | base64 Gives me PRM9hlMDpG0=
Which is 12 chars, not a big deal, but with Python I specified exactly how long the password should be.
With Python, I just used the first example as the anchor and then built more examples. (For example enforce it to be pronounceable by using every second char as vowel, or build a `horse battery staple generator` style password.)