Last active
August 18, 2023 08:24
-
-
Save miredirex/085ec593f10edf28ab730014f82547cc to your computer and use it in GitHub Desktop.
Safely check if your passwords have been leaked (via haveibeenpwned)
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
| #!/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