help strcmp password menue?

13 visualizzazioni (ultimi 30 giorni)
Paul Berkemeier
Paul Berkemeier il 28 Ott 2019
Commentato: Stephen23 il 28 Ott 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 Commenti
Adam
Adam il 28 Ott 2019
What is your question?
Stephen23
Stephen23 il 28 Ott 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

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Debugging and Analysis in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by