Skip to content

Instantly share code, notes, and snippets.

@delitescere
Last active April 10, 2018 04:04
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save delitescere/ebdc0e99d9dddb4fef20ffc7957b55e4 to your computer and use it in GitHub Desktop.
Save delitescere/ebdc0e99d9dddb4fef20ffc7957b55e4 to your computer and use it in GitHub Desktop.
Check a pwned password from the macOS / bash command line
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
}
@delitescere
Copy link
Author

This is a shell function so the history can be amended, removing the password from the history file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment