Skip to content

Instantly share code, notes, and snippets.

@markhuge
Last active July 16, 2016 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markhuge/6e2f755135507599cb4897031a3feccb to your computer and use it in GitHub Desktop.
Save markhuge/6e2f755135507599cb4897031a3feccb to your computer and use it in GitHub Desktop.
Generate random password with openssl

For the pedants (which I can totally be at times):

Base64 uses a reduced character set, so we're generating a less computationally complex string for something like hashcat to chew on, than say, the full ascii character set. Base64 also typically ends with = or == making the pattern even more predictable.

It's still better than hex, and orders of magnitude better than your initials + your grandma's birthday.

# Randpass - generate random password
# Usage: rp [character length]
rp () {
isNumber='^[0-9]+$'
length=32 # default length of 32 chars
if [[ -n "$1" && ! "$1" =~ $isNumber ]]; then
echo "$1 is not a number value. Try again with an actual number, say, 20 =D" >&2
kill -INT $$
fi
if [[ -n "$1" ]]; then
length="$1"
fi
openssl rand -base64 "$length"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment