Skip to content

Instantly share code, notes, and snippets.

@codehearts
Created June 13, 2018 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codehearts/fd57116316339fe547c7d1ac5b500d18 to your computer and use it in GitHub Desktop.
Save codehearts/fd57116316339fe547c7d1ac5b500d18 to your computer and use it in GitHub Desktop.
Check a password against pwnedpasswords.com using k-anonymity
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