필터 지우기
필터 지우기

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 CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by