Last active
November 10, 2018 19:59
-
-
Save camaleaun/c76e612fe99da3bc7f5ada869f4cd01f to your computer and use it in GitHub Desktop.
Generate password like in wp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| rand() { | |
| RANGE=$2 | |
| rand=$RANDOM | |
| let "rand %= $RANGE" | |
| } | |
| generate_password() { | |
| chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' | |
| if $specialchars ; then | |
| chars+='!@#$%^&*()' | |
| fi | |
| if $extraspecialchars ; then | |
| chars+='-_ []{}<>~`+=,.;:/?|' | |
| fi | |
| password='' | |
| i=0 | |
| while [ $i -lt $length ]; do | |
| #echo $i | |
| let i=i+1 | |
| len=${#chars} | |
| let "len -= 1" | |
| rand=0 | |
| rand 0 len | |
| password+=${chars:$rand:1} | |
| done | |
| echo $password | |
| } | |
| length=12 | |
| if [ -n "$1" ]; then | |
| length=$1 | |
| fi | |
| specialchars=true | |
| nospecialchars=false | |
| extraspecialchars=false | |
| args=(`echo "${@:2}" | egrep -o "\-\-(.*)( |=(.*)|$)"`) | |
| for arg in ${args[@]}; do | |
| arg=`echo $arg | sed "s/^--//g"` | |
| name=$arg | |
| value=true | |
| name=`echo "$name" | sed "s/[^0-9a-zA-Z_]//g"` | |
| eval "$name=\$value" | |
| done | |
| if $nospecialchars ; then | |
| specialchars=false | |
| fi | |
| generate_password |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
curl -L -# -o 'genpwd' https://goo.gl/KqqHM7 && chmod +x genpwd && sudo mv genpwd /usr/local/bin/