Hello,
I am new to the whole programming thing and have been trying to make program that will prompt the user to input a 5 character password and follow some rules like certain characters must be numbers, others must be lowercase or uppercase. I have to use an array and Im not really sure how to do it. Ive been trying for the last few days but every thing i tried didn't work out. Any help would be appreciated.
The actual assignment is as follows...
Write a program that will accept a password into a character array string variable. Test for it being a valid password (as per the rules below) and print a message indicating if the entered password is valid or invalid. The rules for an acceptable password are:
the first character must be the letter 'A', 'B', or 'C'
the second character must be a number from 0 -9
the third character must be a number from 0 - 9
the fourth character must be a lower case letter
the fifth character must be a number from 5 - 9
Thank you! In doing this is each character of the password assigned to password[0], password[1]...etc. still? if so, any idea how I would make each character follow its own rule?
It is, including the null term at password[5]. You could use an if statement with logical OR || to check the rule at index 0. For the rules at indexes 1-4 try casting the character as an int and then checking that value for the corresponding ASCII decimal values. The condition for password[2], for example, would be if(!(password[2] > 47 && password[2] < 58))
An expression to match the first three characters by your rules would be something like: "^[ABC][0-9][0-9]"
However, that is probably not what you are looking for.
Now you are looking at one character of input.
Can it be found from word that represents a rule?
In other words, is character X equal to any character in word Y?
In doing this is each character of the password assigned to password[0], password[1]...etc. still? if so, any idea how I would make each character follow its own rule?
Yes. To validate each character you need to check the conditions;
the first character must be the letter 'A', 'B', or 'C'