Added some sanity checks to password hashing scripts.
This commit is contained in:
parent
bc304d9bfa
commit
1f44e3c694
3 changed files with 72 additions and 5 deletions
|
|
@ -4,20 +4,47 @@ set -e
|
|||
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")"
|
||||
|
||||
function hash() {
|
||||
local password="$1"
|
||||
node ./bcrypt.js <<<"$password"
|
||||
}
|
||||
|
||||
function check() {
|
||||
local password="$1"
|
||||
local hash="$2"
|
||||
node ./bcrypt.js "$hash" <<<"$password" > /dev/null
|
||||
}
|
||||
|
||||
while :; do
|
||||
read -sp "Password: " password
|
||||
echo
|
||||
|
||||
if [[ -z "$password" ]]; then
|
||||
echo
|
||||
echo "Your input was empty. Pleas provide a password."
|
||||
echo
|
||||
continue
|
||||
fi
|
||||
|
||||
read -sp "Confirm: " confirmation
|
||||
echo
|
||||
|
||||
if [[ "$password" == "$confirmation" ]]; then
|
||||
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
|
||||
break
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "Passwords do not match, try again."
|
||||
echo "Failed to verify password after hashing. This should not happen."
|
||||
echo
|
||||
done
|
||||
|
||||
exec node ./bcrypt.js <<<"$password"
|
||||
echo
|
||||
echo "$password_hash"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue