Skip to content

Instantly share code, notes, and snippets.

@morten-olsen
Last active July 18, 2019 08:43
Show Gist options
  • Save morten-olsen/4fe43600374fa7913ca9ba53cde6d4e7 to your computer and use it in GitHub Desktop.
Save morten-olsen/4fe43600374fa7913ca9ba53cde6d4e7 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ -n "$1" ]; then
password=$1
else
echo "Password"
read -s password
fi
SHA1_HASH=`printf $password | openssl sha1 | tr a-z A-Z | cut -d"=" -f2 | tr -d " "`
SHA_LOOKUP=`curl -s "https://api.pwnedpasswords.com/range/${SHA1_HASH:0:5}" | egrep -E "^${SHA1_HASH:5:${#SHA1_HASH}-5}"`
if [[ -n "${SHA_LOOKUP/[ ]*\n/}" ]]; then
SHA_RESULTS="${SHA_LOOKUP:${#SHA1_HASH}-4:${#SHA_LOOKUP}-${#SHA1_HASH}+3}"
echo "Password is pwn'ed $SHA_RESULTS times"
exit 105
fi
echo "Password might still be alright"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment