Last active
April 10, 2018 04:04
-
-
Save delitescere/ebdc0e99d9dddb4fef20ffc7957b55e4 to your computer and use it in GitHub Desktop.
Check a pwned password from the macOS / bash command line
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
pwned-passwd () | |
{ | |
history -d $((HISTCMD - 1)); | |
sha=$(printf $1 | sha1sum | cut -d' ' -f1 | tr [:lower:] [:upper:]); | |
prefix=${sha:0:5}; | |
suffix=${sha:5}; | |
count=$(curl -Ss https://api.pwnedpasswords.com/range/$prefix | grep $suffix | cut -d':' -f2); | |
[ -n "$count" ] && echo $count >&2 && return 1; | |
return 0; | |
# Usage: | |
# $ pwned-passwd Today1234 | |
# 147 | |
# $ echo $? | |
# 1 | |
# $ pwned-passwd not-tonight-josephine | |
# $ echo $? | |
# 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a shell function so the history can be amended, removing the password from the history file.