Skip to content

Instantly share code, notes, and snippets.

@pascalandy
Last active May 21, 2020 22:59
Show Gist options
  • Select an option

  • Save pascalandy/e08c25c41d05c12f7a7cd89dcac48d33 to your computer and use it in GitHub Desktop.

Select an option

Save pascalandy/e08c25c41d05c12f7a7cd89dcac48d33 to your computer and use it in GitHub Desktop.
A solid bash script to generate password
#############################################################################
# generate-password.sh
# Source: https://gist.github.com/pascalandy/e08c25c41d05c12f7a7cd89dcac48d33
# License > https://github.com/pascalandy/GNU-GENERAL-PUBLIC-LICENSE/blob/master/README.md
#############################################################################
#
# Here is my crazy ass bash script 🎰 password generator 🎰. Works on Mac and Linux.
# This generates two random passwords at a time:
# The first with some spaces and the other one without spaces.
#
# To increase even more the password security, the lenght is random as well.
# I personally prefer when password ends with 'Zz' so I am sure I know where it ends.
# Enjoy!
#
# Pascal Andy
# twitter.com/_pascalandy
#
#############################################################################
unset GRP1
unset GRP2
unset GRP3
unset GRP4
unset GRP5
unset GRP6
unset GRP_Z
unset PWD_WITH_SPACE
unset PWD_NO_SPACE
#
SUB1=$((RANDOM%8+6))
SUB2=$((RANDOM%8+7))
SUB3=$((RANDOM%8+8))
SUB4=$((RANDOM%8+5))
SUB5=$((RANDOM%8+7))
SUB6=$((RANDOM%8+6))
#
GRP1=$(openssl rand -base64 $SUB1 | cut -c1-$SUB1)
GRP2=$(openssl rand -base64 $SUB2 | cut -c1-$SUB2)
GRP3=$(openssl rand -base64 $SUB3 | cut -c1-$SUB3)
GRP4=$(openssl rand -base64 $SUB4 | cut -c1-$SUB4)
GRP5=$(openssl rand -base64 $SUB5 | cut -c1-$SUB5)
GRP6=$(openssl rand -base64 $SUB6 | cut -c1-$SUB6)
GRP_Z=Zz
#
PWD_WITH_SPACE="$GRP1 $GRP2 $GRP3 $GRP4 $GRP5 $GRP6$GRP_Z"
PWD_NO_SPACE="$GRP1$GRP2$GRP3$GRP4$GRP5$GRP6$GRP_Z"
#
echo
echo $PWD_WITH_SPACE
echo $PWD_NO_SPACE
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment