Your Location is: Home > Linux

I want to break out of my username prompt if its incorrect

From: Korea View: 2050 Jacob Campbell 

Question

Here's what i am trying to do... I have it that it only prompts for a password after the correct Username has been entered but if the incorrect username is entered it gives me an error about my password prompt script.... is there a way that i can loop it back to start if it is incorrect? I want to keep it simple as i am still learning coding in linux and that is about as far as I am...

while [ TRUE ];do
    clear
    read -p "Enter Username: " USERNAME 
#USER ENTERS USERNAME
    
    if [ $USERNAME = "Jacob" -a $PASSWORD = "123" ];then
        if [ $USERNAME = "Jacob" ];then
            echo -e "\n\nVerifying login"
            sleep 1
            echo -e "\n\nUsername is OK!"
            sleep 1
            echo -e "\n\n"
            read -sp "Enter Password: " PASSWORD
#USER ENTERS PASSWORD ONLY AFTER ENTERING A VALID LOGIN
        else
            echo "verifying login"
            sleep 1
            echo "Incorrect username"
            sleep 2 
            break
        fi
        
        if [ $PASSWORD = "123" ];then
            sleep 1
            echo -e "\n\nverifying password!"
            sleep 1 
            echo -e "\n\nPassword OK!" 
            sleep 1
            echo -e "\n\nThis is the way"
            sleep 3
            echo -e "\n\n"
            clear
            break
        else    
            echo "INCORRECT PASSWORD!" 
            sleep 1
            
        fi
done

Best answer