help strcmp password menue?

10 Ansichten (letzte 30 Tage)
Paul Berkemeier
Paul Berkemeier am 28 Okt. 2019
Kommentiert: Stephen23 am 28 Okt. 2019
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 Kommentare
Adam
Adam am 28 Okt. 2019
What is your question?
Stephen23
Stephen23 am 28 Okt. 2019
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

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Debugging and Analysis finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by