my idea:
look what i have got?
%Übung 3 Aufgabe 5
function menue3pkt
disp 'Folgende Menüpunkte'
disp 'A = Admin'
disp 'B = Benutzer'
disp 'C = Programm beenden'
prompt1 = ('Wählen Sie aus dem Menü: ');
x=input(prompt1, 's');
a='2105';
b='2000';
c='0000';
versuche = 0;
while versuche < 3
if x=='A'
prompt2 = ('Bitte Adminpassword eingeben: ');
y = input(prompt2, 's');
z = strcmp(a,y);
switch z
case 1
disp 'passwort richtig'
return
otherwise
disp 'passwort falsch'
versuche = versuche +1;
disp ('Das war Versuch Nummer:')
disp (versuche);
end
elseif x=='B'
prompt2 = ('Bitte Benutzerpassword eingeben: ');
y = input(prompt2, 's');
z = strcmp(b,y);
switch z
case 1
disp 'passwort richtig'
return
otherwise
disp 'passwort falsch'
versuche = versuche +1;
disp ('Das war Versuch Nummer:')
disp (versuche);
end
elseif x=='C'
prompt2 = ('Zum Beenden mit Passwort bestätigen: ');
y = input(prompt2, 's');
z = strcmp(c,y);
switch z
case 1
disp 'passwort richtig'
quit
otherwise
disp 'passwort falsch'
versuche = versuche +1;
disp ('Das war Versuch Nummer:')
disp (versuche);
end
else
disp ('ERROR - Falsche Eingabe')
disp ('Funktion wird beendet')
return
end
end
disp ('keine Versuche mehr übrig')
end

댓글 수: 2

Adam
Adam 2019년 10월 28일
What is your question?
Note that because it is trivially simple to overload any function MATLAB should not be considered safe for storing or processing passwords.
Note that your function does not actually return any output arguments, nor apparently access any classes or nested variables, so although it displays plenty of text, whatever happens inside this function is discarded when it completes.
Rather than using switch like this:
z = strcmp(a,y);
switch z
case 1
...
otherwise
...
end
simply use if:
if strcmp(a,y)
...
else
...
end

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

질문:

2019년 10월 28일

댓글:

2019년 10월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by