Skip to content

Instantly share code, notes, and snippets.

@cmbuckley
Created February 6, 2024 17:27
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 cmbuckley/d11544cca578b1a136d3b03f7ed9df0f to your computer and use it in GitHub Desktop.
Save cmbuckley/d11544cca578b1a136d3b03f7ed9df0f to your computer and use it in GitHub Desktop.
Quick and dirty script to check Have I Been Pwned
#!/bin/bash
echo 'This script checks the HIBP API to see if a password has been breached.'
echo 'Only the first 5 characters of the SHA1 hash of the password leave the device.'
echo
echo -n 'Password: '
read -s password
hash=$(echo -n "$password" | sha1sum | cut -c 1-40)
echo ; echo
echo "Checking HIBP for hash range ${hash:0:5}..."
count=$(curl -Ss "https://api.pwnedpasswords.com/range/${hash:0:5}" | grep -i "${hash:5}" | cut -d: -f2 | tr -d '\r')
[ -z "$count" ] && echo 'Password not pwned' || echo "Password seen $count times before"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment