I need help fixing up my password generator

3 次查看(过去 30 天)
So far my program lets a user input the range of how many characters they want in the password, and also input how many passwords they want generated. My program also checks if the first element of the password is a letter, if it isn't an error is returned to the screen. I have started checking if there is at least one lower case letter in the password as well, but it doesn't seem to be working. All my code is below and I'd really appreciate some help :)
function password_generator
s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
sLength = input('What is your password range: ');
Repeats = input('How many passwords do you want generated: ');
numRands = length(s);
for number_of_passwords = 1: Repeats
[Random_Password] = s(round(rand(1,randi(sLength))*numRands));
disp(Random_Password);
[check] = isstrprop(Random_Password, 'alpha')
if check(1) == 1
else
error('The first element of password is not a letter');
end
[check2] = isstrprop(Random_Password,'lower')
if check2 == 1
else
error('There are no lower case letters in this password')
end
end
end

采纳的回答

the cyclist
the cyclist 2014-5-1
If I understand your intent correctly, I think you want your second check to be
if any(check2 == 1)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Coder 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by