This is what I have so far Help, I am new to bash #!/bin/bash" while true; do read -p "Please Enter Username : " Admin read -p "Please Enter Username again : " Username if [[ "$Username" == "$Admin" ]] then echo "Username is Correct" break; else printf "Username is Wrong" fi done while true; do echo -n "Enter a password: " read -s firstpassword echo read -p "Retype a password: " secondpassword echo if [ $firstpassword == $secondpassword ]; then echo "Password is correct." break; else printf " Password is wrong." fi done
CodePudding user response:
#!/bin/bash
while true; do
read -p "Please Enter Username: " Admin
read -p "Please Enter Username again: " Username
if [[ "$Username" == "$Admin" ]]
then
echo "Username is Correct"
break;
else
printf "Username is Wrong\n"
fi
done
password="1234"
n=0
function login() {
n=$((n 1))
if (( $n > 3 ))
then
echo "To many attempts, terminating.."
return 0
else
echo -n "Enter the password: "
read pwd
if [ $password = $pwd ]
then
echo "Password is correct"
else
echo "Password is incorrect!"
login
fi
fi
}
login
If you wanted to check username also by 3 attempts then
#!/bin/bash
n=0
function login() {
n=$((n 1))
read -p "Please Enter Username: " Admin
read -p "Please Enter Username again: " Username
if [[ "$Username" == "$Admin" ]]
then
echo "Username is Correct"
n=0
password
else
if (( $n >= 3 ))
then
echo "Too many wrong attempts, terminating.."
return 0
else
printf "Username is Wrong\n"
login
fi
fi
}
function password() {
password="1234"
n=$((n 1))
if (( $n > 3 ))
then
echo "Too many attempts, terminating.."
return 0
else
echo -n "Enter the password: "
read pwd
if [ $password = $pwd ]
then
echo "Password is correct"
else
echo "Password is incorrect!"
password
fi
fi
}
login