Clear Filters
Clear Filters

How to make sure user must login first then only they can proceed to next questions.

2 views (last 30 days)
Hi i need help with the coding. I wan to make sure that users must login first before they can choose the next questions from the menu, that means user needs to enter their name and ID first then only after that they can proceed with other questions. Kindly need assistance, thank you.
%Define menu items
menuItems={'Login','Parts to print',,'Quit'};
%Display Menu
choose=DISPMENUSETTING(menuItems);
%Login
if choose==1
name=input('Enter your name:','s');
ID =input('Enter your ID:','s');
%Parts
elseif choose==2
name=input('What type of parts that you want to make?:','s');
%Quit
elseif choose==3
disp('Thank You')
break

Answers (2)

Rohit
Rohit on 11 Jan 2023
Hello,
In order to ask users to login before choosing from other menu options, you can separate the two. First ask the users to login (login screen) and only then show the other options of menu (menu screen).

Walter Roberson
Walter Roberson on 11 Jan 2023
You can use the same logic, just restricted choices if the user has not already logged in.
This version of the code allows the user to log in again after they have already logged in -- for example if they wanted to switch to a different user.
%Define menu items
menuItems={'Login','Parts to print',,'Quit'};
have_logged_in = false;
while true
%Display Menu
thismenu = menuItems;
if ~have_logged_in; thismenu = thismenu(1); end
choose = DISPMENUSETTING(thismenu);
%Login
if choose==1
name=input('Enter your name:','s');
ID =input('Enter your ID:','s');
%Parts
have_logged_in = true;
elseif choose==2
name=input('What type of parts that you want to make?:','s');
%Quit
elseif choose==3
disp('Thank You')
break
end
end

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!