Add script to query pwned password database

master
nirenjan 2019-01-17 14:16:46 -08:00
parent 63656f9fc2
commit 6f89117689
1 changed files with 31 additions and 0 deletions

31
scripts/pwnedpass 100755
View File

@ -0,0 +1,31 @@
#!/bin/bash
# Script to query the pwned passwords database to see if the user
# specified password has been leaked
echo "Query Pwned Passwords Database"
echo "Enter your password, press Ctrl-D to exit"
while read -s -p 'Password: '
do
HASH=$(echo -n "$REPLY" | sha1sum | awk '{ print $1 }')
PREFIX=${HASH:0:5}
SUFFIX=${HASH:5}
RESULT=$(curl -s -XGET https://api.pwnedpasswords.com/range/$PREFIX |
grep -i $SUFFIX)
# Print a newline
echo
if [[ -n "$RESULT" ]]
then
COUNT=${RESULT##*:}
COUNT=${COUNT% }
echo "Password has been found $COUNT times"
else
echo "Password appears to be safe to use"
fi
echo
done