#!/bin/bash

pwd1=''
pwd2=''

trap "stty echo; exit 1" 2

while :
do
  stty -echo
  echo -n "New Password: "
  read pwd1
  echo
  echo -n "Retype new Password: "
  read pwd2
  echo
  if [ ${#pwd1} -lt 8 -o ${#pwd2} -lt 8 ]; then
    echo "It is way too short."
    continue
  fi
  if [ $pwd1 = $pwd2 ]; then
    break
  else
    echo "Sorry, passwords do not match."
  fi
done
stty echo

exit 0
