From 6f8911768937b4e4856c6b4db446c5cad69660ad Mon Sep 17 00:00:00 2001 From: nirenjan Date: Thu, 17 Jan 2019 14:16:46 -0800 Subject: [PATCH] Add script to query pwned password database --- scripts/pwnedpass | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 scripts/pwnedpass diff --git a/scripts/pwnedpass b/scripts/pwnedpass new file mode 100755 index 0000000..b71b191 --- /dev/null +++ b/scripts/pwnedpass @@ -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