I'm writing a program that stores passwords into a char array then checks for 1 upper, lower, number and allows @ - _ .
For some reason it won't read the special chars - unless I include this function, but when I do it only evaluates those in the function, and just ignores all non alpha/numeric characters.
bool valChar(char password[], const int length)
{
bool ch = false;
for(int i = 0; i < length; i++)
{
if(isdigit(password[i]) != 0 || isalpha(password[i]) != 0 || password[i] == '@'|| password[i] == '.'|| password[i] == '-'|| password[i] == '_')
{
ch = true;
cout << endl << password[i] << " " << ch << endl;
}
}
if(ch == false)
{
cout << "\n** INVALID ENTRY **\n";
cout << "\nYour password can only contain the characters\n";
cout << "A-Z, a-z, 0-9, &, _, ., and -\n";
}
return ch;
}
out put:
Please choose 1, 2, or 3.
1. Save a new password
2. Display all passwords
3. Exit
Choose 1, 2, or 3: 1
------ New Entry ------------------------
Please enter your new password: @jlk
Your password must be between 8 and 15 characters in length
Your password was 4Your password must conatin at least one
uppercase charater.Your password must conatin at least one
number.
@ 1
j 1
l 1
k 1
Please enter your new password: jkl^jkl
j 1
k 1
l 1
j 1
k 1
l 1
Please enter your new password:
The out put lists the number and then the boolean outcome when evaluated as per the function up above.
As you can see the first entry the special char is evaluated and placed within the array, but the second it isn't? Can anyone shed some light on this?