Commit 4cae6556 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Make passwd-chk output prettier and more informative

parent 99675727
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
#!/usr/bin/env bash
set -euo pipefail

CHECK='✓'
GREEN=`tput setaf 2`
RED=`tput setaf 1`
BOLD=`tput bold`
RESET=`tput sgr0`

read -sp "password: "; echo
hash=$(printf "$REPLY"|sha1sum|cut -f1 -d\ |tr a-z A-Z)
prefix=$(head -c5 <<<"$hash")
@@ -8,6 +14,8 @@ prefix=$(head -c5 <<<"$hash")
IFS=$'\n\r:'
curl -s https://api.pwnedpasswords.com/range/$prefix|while read suffix count; do
	[[ $prefix$suffix == $hash ]] || continue
	echo "In database $count times"
	echo "${RED}${BOLD}${count}${RESET}${RED}" \
		"people have had their accounts broken into using the password" \
		"\"${REPLY}\".${RESET}"
	exit 1
done && echo "Not in database"
done && echo "${GREEN}Not in database   ${CHECK}${RESET}"