Hello ihtsbryan,
Digging into your program while thinking a solution to your request I noticed some things that could be done better like:
static const char alphanum[] =
"static" is not needed here. I believe that a global variable is "static" by default. Also you could just as easily use
const std::string alphanum{ "0123456789!@#$%^&*()ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" };
Then when you define the variable
stringLength = sizeof(alphanum)
you would write that as
stringLength = alphanum.length()
. Later on tn the program where you use "stringLength" you could use "alphanum.length()".
In line 52 remove the "- 1" otherwise you will never choose "z" from "alphanum" as you are cutting yourself short one position in the string or the array.
Thinking about the verification of the password my first thought is a do/while loop containing a for loop to check each character of the string. This is where the string would work better than the character array. In the for loop you can use the member functions of string like:
if (isdigit(password[i])
http://www.cplusplus.com/reference/cctype/isdigit/
see the window or frame on the left side for other "is" functions. Looks like you will need to include the header file "cctype" to use these functions. Inside the for loop it would look something like this:
1 2 3
|
if (isdigit(passwork[i])
digit = true; // digit is defined as a bool
|
You will need other "if" statements for "isupper", "is lower" etc. The "isgraph" I have not used till now, so I am not sure if it will work for all the special characters. You might have to use "ispunct" to catch any character that "isgraph" does not.
I would define all the bool variables out side the do/while loop and at the start of the do/while I would set all the bool variables to false before you check the "password" string.
After the for loop check all the bool variables, this can be done with one "if" statement. Then if it fails generate a new "password" and start the do/while loop over. If it is true then
break out of the do/while and continue on with the program.
With the testing I have done so far this verification was not really needed, but it is a good idea.
Hope that helps,
Andy