Added some sanity checks to password hashing scripts.

This commit is contained in:
baldo 2022-07-14 10:45:56 +02:00
commit 1f44e3c694
3 changed files with 72 additions and 5 deletions

30
bin/check-passwd.sh Executable file
View file

@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -e
cd "$(dirname "${BASH_SOURCE[0]}")"
if [[ "$#" -ne 1 ]]; then
echo "usage: check-passwd.sh '[password hash]'"
exit 1
fi
password_hash="$1"
if ! [[ "$password_hash" =~ ^\$2[ab]\$[0-9]+\$.{53}$ ]]; then
echo "Invalid password hash. Did you forget to quote it in '...'?"
exit 1
fi
while :; do
read -sp "Password: " password
echo
if node ./bcrypt.js "$password_hash" <<<"$password"; then
break
fi
echo
echo "Passwords do not match, try again."
echo
done