Created
January 21, 2024 20:33
-
-
Save fartbagxp/3af246a2dafad1ddd01e870ecdb5df5b to your computer and use it in GitHub Desktop.
Discover pwd passwords
This file contains hidden or 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 | |
set -eu | |
if [ $# -ne 1 ]; then | |
echo "Usage: $0 <password>" | |
exit 1 | |
fi | |
if command -v curl > /dev/null 2>&1 ; then | |
echo "curl is installed" | |
# curl --version | |
else | |
echo "curl not found! Please install curl and run again!" | |
exit | |
fi | |
if command -v awk > /dev/null 2>&1 ; then | |
echo "awk is installed" | |
# awk --version | |
else | |
echo "awk not found! Please install awk and run again!" | |
exit | |
fi | |
if command -v sha1sum > /dev/null 2>&1 ; then | |
echo "sha1sum is installed" | |
# sha1sum --version | |
else | |
echo "sha1sum not found! Please install sha1sum and run again!" | |
exit | |
fi | |
if command -v grep > /dev/null 2>&1 ; then | |
echo "grep is installed" | |
# grep --version | |
else | |
echo "grep not found! Please install grep and run again!" | |
exit | |
fi | |
password="$1" | |
if [ -z "$password" ]; then | |
echo "Password cannot be empty." | |
exit 1 | |
fi | |
sha1=$(echo -n "$password" | sha1sum | awk '{print $1}') | |
prefix="${sha1:0:5}" | |
URL="https://api.pwnedpasswords.com/range/$prefix" | |
echo "Checking pwd password at ${URL}" | |
response=$(curl -s "https://api.pwnedpasswords.com/range/$prefix") | |
suffix="${sha1:5}" | |
match_line=$(echo "$response" | grep -i "$suffix") | |
if [ -n "$match_line" ]; then | |
echo "Password has been leaked. Matching line:" | |
echo "$match_line" | |
else | |
echo "Password is secure." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment