Skip to content

Instantly share code, notes, and snippets.

@jahil
Last active November 29, 2024 05:53
Show Gist options
  • Save jahil/69768e3b56a092af1df1 to your computer and use it in GitHub Desktop.
Save jahil/69768e3b56a092af1df1 to your computer and use it in GitHub Desktop.
GRC's Perfect Passwords Generator
#!/bin/bash
# GRC's Perfect Passwords Generator
WGET="/usr/bin/wget"
FILE=`tempfile`
$WGET -q --tries=10 --timeout=5 http://www.google.com -O $FILE &> /dev/null
[ -z "$1" ] && echo -e "\E[31mGRC's\E[37m Ultra High Security Password Generator v0.1\r\033[0m" && echo -e '--------------------------------------------------\n' &&
echo -e '\E[37mUsage: ppassword [\E[31m-an alphanumeric\E[37m ] [\E[32m-as ascii\E[37m ] [ -hex hexadecimal ]' && exit 100
case "$1" in
-an)
if [ ! -s $FILE ];then
echo "ERROR: Please check you internet connectivity."
else
curl -s https://www.grc.com/passwords.htm | grep alpha | head -n1 | perl -wlne 'm/font>(.*)<\/font/i && print $1' | sed -e "s/&#xB0;//g" | cut -d" " -f14 | sed 's/size=2>//g'
fi
;;
-as)
if [ ! -s $FILE ];then
echo "ERROR: Please check you internet connectivity."
else
curl -s https://www.grc.com/passwords.htm | grep ASCII | head -n1 | perl -wlne 'm/font>(.*)<\/font/i && print $1' | sed -e "s/&#xB0;//g" | cut -d" " -f14 | sed 's/size=2>//g'
fi
;;
-hex)
if [ ! -s $FILE ];then
echo "ERROR: Please check you internet connectivity."
else
curl -s https://www.grc.com/passwords.htm | grep hexadecimal | head -n1 | perl -wlne 'm/font>(.*)<\/font/i && print $1' | sed -e "s/&#xB0;//g" | cut -d" " -f14 | sed 's/size=2>//g'
fi
;;
*)
echo -e '\E[37mUsage: ppassword [\E[31m-an alphanumeric\E[37m ] [\E[32m-as ascii\E[37m ] [\E[37m -hex hexadecimal ]'
;;
esac
@caseyrichins
Copy link

I've updated this gist to remove the older tempfile syntax with the newer mktemp syntax and added a a trap to remove the temp file for the internet check to ensure a clean filesystem. Even though the file is being written to /tmp I don't like having a bunch of tmp files left over from script executions. Since can't make a pull request on a gist, i'm offering up my fork to update this script.

Fantastic Script though by the way, I'm glad I looked for an existing on before writing my own.

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