I need help fixing up my password generator

조회 수: 3 (최근 30일)
Madeleine
Madeleine 2014년 5월 1일
답변: the cyclist 2014년 5월 1일
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