Skip to content

Instantly share code, notes, and snippets.

@hexaflexahexagon
Created December 20, 2021 14:54
Show Gist options
  • Save hexaflexahexagon/f4c942cc9ef38c65636a639fc46a6131 to your computer and use it in GitHub Desktop.
Save hexaflexahexagon/f4c942cc9ef38c65636a639fc46a6131 to your computer and use it in GitHub Desktop.
# check if a given string was found in the haveibeenpwned breach database
#!/bin/bash
# check if a given string was found in the haveibeenpwned breach database
prefix=$(echo -n "$1" | sha1sum | head -c 5)
suffix=$(echo -n "$1" | sha1sum | cut -c 6- | tr -d ' '-)
output=$(curl -s "https://api.pwnedpasswords.com/range/$prefix" \
-H 'user-agent: asdf' |\
grep -i "$suffix" )
if [ "$output" == "" ]; then
echo "Password not found in any breach!"
exit 0
else
echo -n "Password find count: "
echo -n "$output" | cut -d':' -f2 | sed 's/ //'
# Why does this newline with -n?
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment