Azzera filtri
Azzera filtri

Creating a password checker using a function

7 visualizzazioni (ultimi 30 giorni)
Jacob Kiem
Jacob Kiem il 27 Mag 2018
Commentato: Jacob Kiem il 27 Mag 2018
So im trying to create a password checker that checks for: length of at least 8 characters 1 upper case and 1 lower case but im stuck. This is what i have so far but none of it is working
if true
% code
function [len] = isValidPasswordFUNC(password)
% A function that checks a password to be valid
% Checking the length of the password
len = length(password)
if len < 8
disp('Invalid password is too short');
else
disp('Password is Valid length');
end
Then the script:
if true
% code
close all
clear
clc
password = input('Enter your password: ');
function [len] = isValidPasswordFUNC(password);
end
Thanks any help or a point in a direction is very helpful thanks

Risposte (1)

Guillaume
Guillaume il 27 Mag 2018
Modificato: Guillaume il 27 Mag 2018
Sounds like homework, so I won't give you the solution. I'll just tell you to have a look at isstrprop.
Also, should your checking function return the length of the password or an indication of whether or not the password is valid? The latter would make more sense to me.
  1 Commento
Jacob Kiem
Jacob Kiem il 27 Mag 2018
I have this so far but it only works up to checking the upper case letters. I have also tried to make it a function but not working or displaying anything.
if true
% code
close all
clear
clc
password = input('What is your password: ','s');
L = strlength(password);
if L < 8
disp('Invalid amount of characters')
else
disp('Valid amount of characters')
end
TU = isstrprop(password,'upper');
if TU >= 1
disp('Valid amount of upper case characters');
else
disp('Invalid amount of upper case characters');
end
TL = isstrprop(password,'lower')
if TL >= 1
disp('Valid amount of lower case characters');
else
disp('Invalid amount of lower case characters');
end
TN = isstrprop(password, 'digit');
if TN >= 1
disp('Valid amount of numerical characters');
else
disp('Invalid amount of numerical characters');
end
end

Accedi per commentare.

Categorie

Scopri di più su Data Type Conversion 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