Last active
October 10, 2018 12:42
-
-
Save alxndrsn/bc392580c183e03630116608a52e1951 to your computer and use it in GitHub Desktop.
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 | |
# Don't forget to `unset HISTFILE` before using this script ;¬) | |
# | |
# Check your password against Troy Hunt's massive password database. | |
# https://www.troyhunt.com/ive-just-launched-pwned-passwords-version-2/ | |
full_hash="$(node -e " | |
const crypto = require('crypto'); | |
const shasum = crypto.createHash('sha1'); | |
shasum.update('${@}'); | |
console.log(shasum.digest('hex')); | |
")" | |
hash_start="${full_hash:0:5}" | |
hash_end="${full_hash:5:35}" | |
echo "Full hash: $full_hash" | |
echo "Hash start: $hash_start" | |
echo "Hash end: $hash_end" | |
match_count="$(curl "https://api.pwnedpasswords.com/range/${hash_start}" 2>/dev/null | | |
grep -i "^$hash_end:" | | |
cut -d: -f2 | | |
grep -Eo '\d*')" | |
if [ -z "$match_count" ]; then | |
echo 'Your password does not appear in the database :¬)' | |
else | |
echo "Your password has been pwned ${match_count} times :¬o" | |
echo "You'd better change that, quick!" | |
exit 999 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment