Last active
June 7, 2023 08:08
-
-
Save zeusdeux/84b29b2ab277047dfe4591d0e484e71e to your computer and use it in GitHub Desktop.
Check if any passwords have been compromised using HIBP's password API (https://haveibeenpwned.com/API/v2#PwnedPasswords). Your password never leaves your local system!
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
#!/usr/bin/env bash | |
# enable when debugging | |
# set -o errexit | |
# set -o errtrace | |
# set -o xtrace | |
# set -o nounset | |
# set -o pipefail | |
plsno () { | |
if [ -z $1 ]; then | |
echo -e "\e[31mPlease provide a password to check if it has been pwned." 1>&2 # write to stderr | |
echo -e "\e[34mUsage: <space so that it doesn't get saved to bash_history>plsno <password>\e[0m" 1>&2 | |
return 1 | |
fi | |
local PASS_SHA1=$(echo -n $1 | shasum | cut -d' ' -f1) | |
local PASS_SHA1_PREFIX=$(echo -n $PASS_SHA1 | cut -c1-5) | |
local PASS_SHA1_SUFFIX=$(echo -n $PASS_SHA1 | cut -c6-) | |
local PASS_PWNED=$(curl -s "https://api.pwnedpasswords.com/range/${PASS_SHA1_PREFIX}" | grep -i "${PASS_SHA1_SUFFIX}") | |
local PASS_PWNED_COUNT=$(echo -n $PASS_PWNED | cut -d':' -f2 | tr -s ' ') | |
if [ -z "${PASS_PWNED}" ]; then | |
echo -e "\e[32mThis password is \e[1mNOT PWND\e[21m. You can sleep peacefully at night.\e[0m" | |
else | |
echo -ne "\e[1m\e[31m\"${1}\" is PWNED! :( " | |
echo "Please change this password NOW on all affected accounts." | |
echo -ne "\e[0m\e[90mTimes found ->" $PASS_PWNED_COUNT | |
echo -e "\e[0m" | |
fi | |
return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
plsno "password"