Skip to content

Instantly share code, notes, and snippets.

@valerytschopp
Last active March 15, 2019 15:50
Show Gist options
  • Save valerytschopp/0094198fa5bfb8da5e708183c203d1f1 to your computer and use it in GitHub Desktop.
Save valerytschopp/0094198fa5bfb8da5e708183c203d1f1 to your computer and use it in GitHub Desktop.
Check a password against https://haveibeenpwned.com/
#!/bin/bash
read -s -p "Password: " password
echo
hash=$(echo -n $password | sha1sum | awk '{print toupper($1)}')
prefix=${hash:0:5}
response=$(curl -s https://api.pwnedpasswords.com/range/$prefix)
while IFS=':' read -ra line
do
hash_line="$prefix${line[0]}"
count=$(echo ${line[1]}|tr -d '\r')
if [ "$hash_line" == "$hash" ]; then
echo "Password '$password' breached $count times."
exit 1
fi
done <<< "$response"
echo "Password not found in breached database."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment