I'm working on a password validator program and I can't understand why it continues to crash. Visual studio throws a debug assertion failed. My code is below. The problem seems to occur when the program reaches the isupper check. I'm not sure if I'm using this function incorrectly or not. Basically I need to loop through each character of a cstring and check if there is at least one upper case and one lower case character. Any feedback would be greatly appreciated.
How long is the password you are entering? You allow space for 12 characters in your array, make sure that you leave a place for the terminating \0 character on the 12th place. (Do not enter a password more than 11 chars long.)
In your isValidPassword() function, you have a logical error in how you are checking if the password is valid. It is always going to be false.
You could make two bool variables, one for "upperFound" and one for "lowerFound". Then set them equal to false. Set them true in the loop if you find them in the string. Last, set valid = upperFound && lowerFound;
I'm not getting any errors when compiling with MinGW, but I can tell you this: all characters are either upper case, lower case, or neither, so all passwords are invalid.
Hi psault. I'm only entering a 7 character password. My understanding of the logic I wrote was to start valid = true and if any of the conditions were failed, then set valid to false. In line 34, if isupper never finds an upper case character, I would set valid to false. All I would need is one occurance for it to fail. Not sure if this thinking is wrong? Also, since this may be a login error, any idea why this might be crashing the program?
Aside from the logic issue, any ideas why the program might be crashing?
Edit: So it seems the error only occurs if I enter a password less than 11 characters. If I enter 11 characters exactly, the program executes correctly. Any ideas?
If you enter less then 11, there might be garbage data after the \0 that you are reading. You probably want to check up length in your for loop instead of SIZE.