Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

commented Mar 19, 2018

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
You can’t perform that action at this time.