Skip to content

Instantly share code, notes, and snippets.

@michaeljensen
Forked from jbrzozoski/pwtest.sh
Last active January 10, 2023 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaeljensen/930bf1ac768fe301585da5f3a8ddbdc6 to your computer and use it in GitHub Desktop.
Save michaeljensen/930bf1ac768fe301585da5f3a8ddbdc6 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