Skip to content

Instantly share code, notes, and snippets.

@fuzziebrain
Last active September 28, 2021 00:53
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 fuzziebrain/5e731777811a38ced0d43b3714c6b890 to your computer and use it in GitHub Desktop.
Save fuzziebrain/5e731777811a38ced0d43b3714c6b890 to your computer and use it in GitHub Desktop.
Password generator with Bash
# SC => special characters allowed
SC="_"
while
_password=$(openssl rand -base64 $(($RANDOM % 6 + 15)) | tr '[:punct:]' $SC)
[[
$(echo $_password | grep -o '['$SC']' | wc -l) -lt 2
|| $(echo $_password | grep -o '[0-9]' | wc -l) -lt 2
|| $(echo $_password | grep -o '[A-Z]' | wc -l) -lt 2
|| $(echo $_password | grep -o '[a-z]' | wc -l) -lt 2
]]
do true; done
echo $_password
# Example Use
# ===========
# RANDOM_SECRET=$(sh -c "$(curl -fsSL https://gist.githubusercontent.com/fuzziebrain/5e731777811a38ced0d43b3714c6b890/raw/e6b63c6386a59d8cb943094e43f81b6f58f662d0/generate_password.sh)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment