#!/bin/bash
unset PASSWORD
unset CHARCOUNT
echo -n "Login:";
read login_name;
echo -n "Enter password: "
stty -echo
CHARCOUNT=0
while IFS= read -p "$PROMPT" -r -s -n 1 CHAR
do
# Enter - accept password
if [[ $CHAR == $'\0' ]] ; then
break
fi
# Backspace
if [[ $CHAR == $'\177' ]] ; then
if [ $CHARCOUNT -gt 0 ] ; then
CHARCOUNT=$((CHARCOUNT-1))
PROMPT=$'\b \b'
PASSWORD="${PASSWORD%?}"
else
PROMPT=''
fi
else
CHARCOUNT=$((CHARCOUNT+1))
PROMPT='*'
PASSWORD+="$CHAR"
fi
done
stty echo
if [[ $login_name == "pearl" && $PASSWORD == "pearlyperl" ]] ; then
echo -e "\n Login Successful :-) \n";
else
echo -e "Login Failed \n";
fi
unset PASSWORD
unset CHARCOUNT
echo -n "Login:";
read login_name;
echo -n "Enter password: "
stty -echo
CHARCOUNT=0
while IFS= read -p "$PROMPT" -r -s -n 1 CHAR
do
# Enter - accept password
if [[ $CHAR == $'\0' ]] ; then
break
fi
# Backspace
if [[ $CHAR == $'\177' ]] ; then
if [ $CHARCOUNT -gt 0 ] ; then
CHARCOUNT=$((CHARCOUNT-1))
PROMPT=$'\b \b'
PASSWORD="${PASSWORD%?}"
else
PROMPT=''
fi
else
CHARCOUNT=$((CHARCOUNT+1))
PROMPT='*'
PASSWORD+="$CHAR"
fi
done
stty echo
if [[ $login_name == "pearl" && $PASSWORD == "pearlyperl" ]] ; then
echo -e "\n Login Successful :-) \n";
else
echo -e "Login Failed \n";
fi
OUPUT:
./login.sh
Login:pearl
Enter password: **********
Login Successful :-)
No comments:
Post a Comment