Last active
July 18, 2019 08:43
-
-
Save morten-olsen/4fe43600374fa7913ca9ba53cde6d4e7 to your computer and use it in GitHub Desktop.
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 | |
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