Created
December 20, 2021 14:54
-
-
Save hexaflexahexagon/f4c942cc9ef38c65636a639fc46a6131 to your computer and use it in GitHub Desktop.
# check if a given string was found in the haveibeenpwned breach database
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
#!/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