Last active
March 15, 2019 15:50
-
-
Save valerytschopp/0094198fa5bfb8da5e708183c203d1f1 to your computer and use it in GitHub Desktop.
Check a password against https://haveibeenpwned.com/
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 | |
read -s -p "Password: " password | |
echo | |
hash=$(echo -n $password | sha1sum | awk '{print toupper($1)}') | |
prefix=${hash:0:5} | |
response=$(curl -s https://api.pwnedpasswords.com/range/$prefix) | |
while IFS=':' read -ra line | |
do | |
hash_line="$prefix${line[0]}" | |
count=$(echo ${line[1]}|tr -d '\r') | |
if [ "$hash_line" == "$hash" ]; then | |
echo "Password '$password' breached $count times." | |
exit 1 | |
fi | |
done <<< "$response" | |
echo "Password not found in breached database." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment