Created
June 13, 2018 17:02
-
-
Save codehearts/fd57116316339fe547c7d1ac5b500d18 to your computer and use it in GitHub Desktop.
Check a password against pwnedpasswords.com using k-anonymity
This file contains 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
checkpw() { | |
local pw sha shortsha suffixsha breachcount | |
read -srp '> ' pw | |
sha="$(echo -n "$pw" | sha1sum | cut -d' ' -f1)" | |
shortsha="$(echo -n "$sha" | cut -c-5)" | |
suffixsha="${sha#$shortsha}" | |
breachcount="$(curl -s https://api.pwnedpasswords.com/range/$shortsha | grep -i $suffixsha | cut -d':' -f2)" | |
if [ -z $breachcount ]; then | |
printf '\e[0;32mNot compromised\n\e[0m' | |
else | |
printf '\e[0;31mCOMPROMISED: found %s times\n\e[0m' "$breachcount" | |
fi | |
unset pw | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment