help strcmp password menue?

조회 수: 9 (최근 30일)
Paul Berkemeier
Paul Berkemeier 2019년 10월 28일
댓글: Stephen23 2019년 10월 28일
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?
Stephen23
Stephen23 2019년 10월 28일
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개)

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by