help strcmp password menue?

9 visualizaciones (últimos 30 días)
Paul Berkemeier
Paul Berkemeier el 28 de Oct. de 2019
Comentada: Stephen23 el 28 de Oct. de 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 comentarios
Adam
Adam el 28 de Oct. de 2019
What is your question?
Stephen23
Stephen23 el 28 de Oct. de 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

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Debugging and Analysis en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by