Skip to content

Instantly share code, notes, and snippets.

@dshoreman
Created January 17, 2019 10:52
Show Gist options
  • Save dshoreman/3c48ec1638a0def5ec7f2f03e60c357c to your computer and use it in GitHub Desktop.
Save dshoreman/3c48ec1638a0def5ec7f2f03e60c357c to your computer and use it in GitHub Desktop.
PwnedPasswords API Checker (Bash)
#!/bin/bash
# This script checks the haveibeenpwned 'PwnedPasswords'
# API based on the first 5 characters of your password's
# SHA-1 hash, then plucks out a full match from the hash
# suffixes returned by the API (assuming there are any).
# If your password's hash is found, it'll return pwncount.
#
# Either replace $1 with password, or call from shell
# as ` ./passcheck "mypass" - note the preceeding space
# to prevent the command being appended to the history!
#
PASSWD=$1
SHAFUL=$(echo -n $PASSWD | sha1sum | awk '{print $1}')
SHAPRE=$(echo $SHAFUL | awk '{print substr($1,0,5)}')
SHASUF=$(echo $SHAFUL | awk '{print substr($1,6)}')
echo "Searching Pwned Passwords API for SHA-1 prefix '$SHAPRE'"
echo " Full hash: $SHAFUL"
echo
RESPONSE=$(curl "https://api.pwnedpasswords.com/range/$SHAPRE" 2>/dev/null | \grep -i "$SHASUF")
echo ${RESPONSE#*:}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment