Password Strength Indicator Functions help you abstract away complex operation,
ID: 3802550 • Letter: P
Question
Password Strength Indicator Functions help you abstract away complex operation, but they also help you build reusable components. Create a MATLAB function that determines the complexity of a given password based on these rules: A very weak password contains only numbers and is fewer than eight characters. A very weak password contains only letters and is fewer than eight characters. A weak password contains letters and at least one number and is fewer than eight characters. A strong password contains only numbers and is at least eight characters. A strong password contains letters and is at least eight characters. A very strong password contains letters and numbers and is at least eight characters. Constraints: Create a passwordValidator function that takes in password as its argument and returns a string specifying the password strength. Example Output The password '12345' is a very weak password The password 'adcd' is a very weak password The password 'adcd5' is a weak password The password 'adcdefgh' is a strong password The password '123456789' is a strong password The password 'abcd123xyz' is a very strong passwordExplanation / Answer
Here is the code for you:
function strength = passwordValidator(string)
% A very weak password contains only numbers and is fewer than 8
% characters.
% A very weak password contains only letters and is fewer than 8
% characters.
% A weak password contains letters and at least one number, and is fewer
% than 8 characters.
% A strong password contains only numbers and is atleast 8 characters.
% A strong password contains letters and is atleast 8 characters.
% A very strong pasword contains letters and numbers and is atleast 8
% characters.
if sum(isstrprop(string,'alpha')) == 0 && sum(isstrprop(string,'digit')) > 0 && length(string) < 8
strength = 'very weak';
else if sum(isstrprop(string,'alpha')) > 0 && sum(isstrprop(string,'digit')) == 0 && length(string) < 8
strength = 'very weak';
else if sum(isstrprop(string,'alphanum')) > 0 && length(string) < 8
strength = 'weak';
else if sum(isstrprop(string,'digit')) > 0 && sum(isstrprop(string,'alpha')) == 0 && length(string) >= 8
strength = 'strong';
else if sum(isstrprop(string,'digit')) == 0 && sum(isstrprop(string,'alpha')) > 0 && length(string) >= 8
strength = 'strong';
else if sum(isstrprop(string,'alphanum')) > 0 && length(string) >= 8
strength = 'very strong';
end
end
end
end
end
end
end