Skip to content

Instantly share code, notes, and snippets.

@camaleaun
Last active November 10, 2018 19:59
Show Gist options
  • Select an option

  • Save camaleaun/c76e612fe99da3bc7f5ada869f4cd01f to your computer and use it in GitHub Desktop.

Select an option

Save camaleaun/c76e612fe99da3bc7f5ada869f4cd01f to your computer and use it in GitHub Desktop.
Generate password like in wp
#!/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
@camaleaun

Copy link
Copy Markdown
Author

curl -L -# -o 'genpwd' https://goo.gl/KqqHM7 && chmod +x genpwd && sudo mv genpwd /usr/local/bin/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment