フィルターのクリア

Creating a password checker using a function

7 ビュー (過去 30 日間)
Jacob Kiem
Jacob Kiem 2018 年 5 月 27 日
コメント済み: Jacob Kiem 2018 年 5 月 27 日
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

回答 (1 件)

Guillaume
Guillaume 2018 年 5 月 27 日
編集済み: Guillaume 2018 年 5 月 27 日
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 件のコメント
Jacob Kiem
Jacob Kiem 2018 年 5 月 27 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by