Apr 4, 2015 at 10:13pm Apr 4, 2015 at 10:13pm UTC
[Line 86] You need to use:
if (password [cnt] == '\0' )
Apr 5, 2015 at 4:09am Apr 5, 2015 at 4:09am UTC
i fixed that but that is not the main problem. my input disappears after i call it. When i check for it it displays then it just vanishes and i don't know why.
Apr 5, 2015 at 6:34am Apr 5, 2015 at 6:34am UTC
There are many errors in your program, I check them all and rewrite it, it should look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
#include <iostream>
#include <string>
#include <iomanip>
#include <cstring>
#define SIZE 50
using namespace std;
void getInput(char password[]);
bool checkLength (char password[]);
bool checkUpperCase (char password[]);
bool checkLowerCase (char password[]);
bool checkDigit (char password[]);
bool checkAlpha (char password[]);
bool checkWhiteSpace (char password[]);
int main()
{
char input[SIZE], myPassword[SIZE];
bool inputLength;
bool inputUpperCase;
bool inputLowerCase;
bool inputDigit;
bool inputAlpha;
bool inputWhiteSpace;
getInput (input);
inputLength = checkLength(input);
inputUpperCase = checkUpperCase(input);
inputLowerCase = checkLowerCase(input);
inputDigit = checkDigit(input);
inputAlpha = checkAlpha(input);
inputWhiteSpace = checkWhiteSpace(input);
if (inputLength && inputLowerCase && inputDigit &&
inputUpperCase && inputAlpha && inputWhiteSpace)
cout << "The password is legal.\n" ;
return 0;
}
void getInput(char password[])
{
cout << "Please enter a valid password: " ;
cin.getline (password,SIZE);
}
bool checkWhiteSpace (char password[])
{
bool iswhitespace = true ;
string t = password;
for (int cnt = 0; password[cnt] != '\0' ; cnt++)
{
if (password[cnt] == ' ' )
{
cout << "Error, password must not contain any whitespace.\n" ;
return false ;
}
}
return true ;
}
bool checkLength (char password[])
{
int numChar = 0, cnt = 0;
while (password[cnt++] != '\0' )
numChar++;
if ((numChar >= 6) && (numChar <= 13))
return true ;
cout << "Error,Must be at least 6 characters long and up to 13.\n" ;
return false ;
}
bool checkLowerCase(char password[])
{
for (int cnt = 0; password[cnt] != '\0' ; cnt++)
{
if (islower(password[cnt]))
return true ;
}
cout << "Error, password must contain at least one lower case letter.\n" ;
return false ;
}
bool checkUpperCase(char password[])
{
for (int cnt = 0; password[cnt] != '\0' ; cnt++)
{
if (isupper(password[cnt]))
return true ;
}
cout << "Error, password must contain at least one upper case letter.\n" ;
return false ;
}
bool checkDigit(char password[])
{
for (int cnt = 0; password[cnt] != '\0' ; cnt++)
{
if (isdigit(password[cnt]))
return true ;
}
cout << "Error, password must contain at least one digit.\n" ;
return false ;
}
bool checkAlpha (char password[])
{
for (int cnt = 0; password[cnt] != '\0' ; cnt++)
{
if (!isdigit(password[cnt]))
return true ;
}
cout << "Error, password must contain at least one symbol that is not numeric.\n" ;
return false ;
}
And I tested the program, it worked well. :-))
Last edited on Apr 5, 2015 at 6:35am Apr 5, 2015 at 6:35am UTC
Apr 5, 2015 at 1:32pm Apr 5, 2015 at 1:32pm UTC
Thanks a lot Terrison, i was working on it last night but i forgot to check the website. Thank you again