Skip to content

Instantly share code, notes, and snippets.

@jbrzozoski
Created March 3, 2019 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jbrzozoski/cf79710d2eafc98bf9de5a11315e5818 to your computer and use it in GitHub Desktop.
Save jbrzozoski/cf79710d2eafc98bf9de5a11315e5818 to your computer and use it in GitHub Desktop.
Simple bash script to safely check passwords against the pwnedpasswords.com API
#!/bin/bash
# Get a password from the user...
while read -s -p "Enter password to check or Ctrl-C to quit: " pass2check
do
# Output a blank line to clean up output...
echo
# Get the SHA1 of the entered password...
sha1sum_output=`echo -n ${pass2check} | sha1sum`
# Pull apart the head and tail as needed by the pwnedpasswords API...
hash_prefix=${sha1sum_output:0:5}
hash_tail=${sha1sum_output:5:35}
#echo "SHA1: ${sha1sum_output} PREFIX: ${hash_prefix} TAIL: ${hash_tail}"
# Download that chunk of the hash table and look for a match (output if found)
wget --quiet "https://api.pwnedpasswords.com/range/${hash_prefix}" -O - | grep -i "${hash_tail}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment