Skip to content

Instantly share code, notes, and snippets.

@wikrie
Created April 19, 2018 14:08
Show Gist options
  • Save wikrie/8cc1828d65b6c82000285ad7b4ac935a to your computer and use it in GitHub Desktop.
Save wikrie/8cc1828d65b6c82000285ad7b4ac935a to your computer and use it in GitHub Desktop.
Check if password is powned by https://haveibeenpwned.com
#!/bin/bash
# check if password was insert
if [ $# -eq 0 ]
then
echo "no password was insert, syntax is ./check-password.sh password"
else
#create sha1sum of password for transfering to online check
sha1pass=`echo -n "$1" | sha1sum | cut -d ' ' -f1`
#run test and get a result from api
result=`curl -s https://api.pwnedpasswords.com/pwnedpassword/$sha1pass`
# if password was found we will get a number of entries only if result is empty the password was not found, so we check if result is empty
if [ -z "$result" ]
then
echo "Your lucky your password was not found in the Database!"
else
echo "Your password was found: $result times."
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment