Skip to content

Instantly share code, notes, and snippets.

@mino98
Last active March 14, 2018 23:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mino98/8aa240fa55a8182198fba58fb810b366 to your computer and use it in GitHub Desktop.
Save mino98/8aa240fa55a8182198fba58fb810b366 to your computer and use it in GitHub Desktop.
Check password against pwnedpasswords repo.
#!/bin/bash
# Original:
# https://blog.cloudflare.com/validating-leaked-passwords-with-k-anonymity
echo -n Password:
read -s password
echo
hash="$(echo -n $password | openssl dgst -sha1 -binary | xxd -p)"
upperCase="$(echo $hash | tr '[a-z]' '[A-Z]')"
prefix="${upperCase:0:5}"
response=$(curl -s https://api.pwnedpasswords.com/range/$prefix)
while read -r line; do
lineOriginal="$prefix$line"
if [ "${lineOriginal:0:40}" == "$upperCase" ]; then
howmany=$(echo $lineOriginal | cut -d":" -f2 | tr -d "\n\r")
echo "Password breached $howmany times!"
exit 1
fi
done <<< "$response"
echo "Password not found in breached database."
exit 0
@mino98
Copy link
Author

mino98 commented Feb 22, 2018

@mino98
Copy link
Author

mino98 commented Feb 22, 2018

Changed the openssl oneliner to support modern versions.

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