Skip to content

Instantly share code, notes, and snippets.

@miredirex
Last active August 18, 2023 08:24
Show Gist options
  • Select an option

  • Save miredirex/085ec593f10edf28ab730014f82547cc to your computer and use it in GitHub Desktop.

Select an option

Save miredirex/085ec593f10edf28ab730014f82547cc to your computer and use it in GitHub Desktop.
Safely check if your passwords have been leaked (via haveibeenpwned)
#!/bin/sh
read -p 'Password: ' password
hash=`echo -n $password | sha1sum | awk '{ print $1 }'`
echo
echo SHA1 hash: $hash
prefix=${hash:0:5}
suffix=${hash:5:40}
stats=`curl --silent https://api.pwnedpasswords.com/range/$prefix | grep -i $suffix`
echo
echo haveibeenpwned.com says...
echo
bold=$(tput bold)
normal="$(tput sgr0)"
if [ -z "$stats" ]
then
echo "Your password has ${bold}never${normal} been leaked in data breaches"
else
leaked_count=${stats:36}
echo "Your password appeared ${bold}${leaked_count}${normal} time(s) in data breaches"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment