2022-07-11 13:24:15 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")"
|
|
|
|
|
2022-07-14 10:45:56 +02:00
|
|
|
function hash() {
|
|
|
|
local password="$1"
|
|
|
|
node ./bcrypt.js <<<"$password"
|
|
|
|
}
|
|
|
|
|
|
|
|
function check() {
|
|
|
|
local password="$1"
|
|
|
|
local hash="$2"
|
|
|
|
node ./bcrypt.js "$hash" <<<"$password" > /dev/null
|
|
|
|
}
|
|
|
|
|
2022-07-11 13:24:15 +02:00
|
|
|
while :; do
|
|
|
|
read -sp "Password: " password
|
|
|
|
echo
|
|
|
|
|
2022-07-14 10:45:56 +02:00
|
|
|
if [[ -z "$password" ]]; then
|
|
|
|
echo
|
|
|
|
echo "Your input was empty. Pleas provide a password."
|
|
|
|
echo
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2022-07-11 13:24:15 +02:00
|
|
|
read -sp "Confirm: " confirmation
|
|
|
|
echo
|
|
|
|
|
2022-07-14 10:45:56 +02:00
|
|
|
if ! [[ "$password" == "$confirmation" ]]; then
|
|
|
|
echo
|
|
|
|
echo "Passwords do not match, try again."
|
|
|
|
echo
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
password_hash=$(hash "$password")
|
|
|
|
if check "$password" "$password_hash"; then
|
2022-07-11 13:24:15 +02:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo
|
2022-07-14 10:45:56 +02:00
|
|
|
echo "Failed to verify password after hashing. This should not happen."
|
2022-07-11 13:24:15 +02:00
|
|
|
echo
|
|
|
|
done
|
|
|
|
|
2022-07-14 10:45:56 +02:00
|
|
|
echo
|
|
|
|
echo "$password_hash"
|