Creating a password checker using basic programming
Mostrar comentarios más antiguos
What I am trying to do here is to create a program to check whether the input is identical to set password by only using the basics.(if, for, while and such)
The program would need to ask for a password until a correct one is entered.
the code I intended to write was:
key = 'test1234'
x = input('Enter the password: ','s') ;
while strlength(x) ~= 6
if strlength(x) ~= 6
fprintf('\nInput = %s',x)
fprintf('\nPassword is incorrect.')
x = input('Enter the password: ','s')
else strlength(x) == 6
break
end
end
while x ~= key
if x ~= key
fprintf('\nInput = %s',x)
fprintf('\nPassword is incorrect.')
x = input('Enter the password: ','s')
else x == key
break
end
end
fprintf('Password is correct.')
the problem I faced at first was that the use of == function would only work if the key and the input had the same length. Otherwise then it would only pop an error, so I merely made it so that it would check for the length of the password first.
But then after entering 6 length input that is not identical to the desired key, the program would move on to the next criteria and thus pop another error when the next input isn't 6-long.
I am literally new to programming stuff so any help would be appreciated.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre MATLAB Coder en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!