Hello guys
Down here I have a code that lets a user login into a system, as well as create an account. My question is: How can I loop this same code every time the user creates an account (chooses option 2, specifies username and password, and then shows the same menu(in case the user wants to create another account)).
I know bash doesn't have a goto option so I tried wrapping this whole piece of code into a function, but without luck (I miss something) . :/
Thanks for the help.
Down here I have a code that lets a user login into a system, as well as create an account. My question is: How can I loop this same code every time the user creates an account (chooses option 2, specifies username and password, and then shows the same menu(in case the user wants to create another account)).
I know bash doesn't have a goto option so I tried wrapping this whole piece of code into a function, but without luck (I miss something) . :/
Thanks for the help.
Code
echo
echo
welcomeMessage #welcome message function
echo
echo 1: Login #login option
echo 2: Create account #create account option
echo
echo Enter your option:
read options #read option
case $options in
"1") #login
echo Enter Username
read username #read username entered
grabUser #function to check if username exists and return 1 if he exists
if [ "$userResult" == 1 ]; then
enterPass #prompt password field
else
userResult=0
while [ "$userResult" == 0 ]; do
echo -n Try again:
read username
grabUser
done
enterPass
fi
grabPass #function to check if password exists and return 1 if it exists
if [ "$passResult" == 1 ]; then
echo
echo
welcomeASCII
else
passResult=0
while [ "$passResult" == 0 ]; do
echo Try again:
read -s password
grabPass
done
echo
echo
welcomeASCII #welcome screen ASCII function
fi
echo
echo
;;
"2") #create user option
echo Create Username:
read username
grabUser
while true; do #while grabUser grabs username
if [ "$userResult" == 0 ]; then #if username doesn't exist
insertUser #add user to db
enterPass #prompt password field
insertPass #add password to db
else
userResult=1
while [ "$userResult" == 1 ]; do #loop until user doesn't exist
echo Try Again
read username
grabUser
done
insertUser
enterPass
insertPass
fi
done
esac
