I am struggling on the "Password Verification" problem

I have been working on this problem for a while and I cannot get the program to accept my arguments. The problem requires a password to be at least six characters long, have at least 1 lower and uppercase letter, and 1 digit. The program should verify if password is acceptable or not. I do not have any error messages, but the program does not work when the listed criteria is entered. Here is what I coded:

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
class="centertext">
/******************************* Password Verifier *******************************/ # include <iostream> // i/o header file # include <cctype> // header file needed for testing characters (e.g., isupper()) # include <cstring> //header file needed for using strlen() function using namespace std; bool testUpper (char []); //function prototype for function testUpper bool testLower (char []); //function prototype for function testLower bool testDigit (char []); //function prototype for function testDigit bool pswordVerify(char []); // function prototype for function pswordVerify /**************************** Function Main *****************************/ int main () { const int LENGTH = 100; // Maximum length of string char password[LENGTH]; // array allows up to 100 characters for a password //Program Introduction cout << "PASSWORD VERIFICATION\n\n"; cout << "Please create a password using only 6 characters. "; cout << "The password must contain at\nleast 1 uppercase letter, "; cout << "1 lowercase letter, and 1 digit.\n"; cin.getline(password, LENGTH); //user enters password // Congratulatory message if passoword is valid if (pswordVerify(password)) cout << "Password accepted!\n"; //Loops error message while password is invalid while (!pswordVerify(password)) { cout << "please enter a valid entry.\n"; cout << "A valid password requires at least the following:\n\n"; cout << "A password must be at least 6 characters. "; cout << "1 uppercase letter, 1 lowercase\nletter, and 1 digit "; cout << "(0 through 9).\n"; cin.getline(password, LENGTH); //user reenters password } return 0; } /************************************************************ Function pswordVerify is used to verify the characters enter has at least 1 digit, 1 lowercase letter, and 1 upercase letter. The password must be at least 6 characters long *************************************************************/ bool pswordVerify(char psword []) { bool result =false; int length = strlen(psword); testUpper(psword); testLower (psword); testDigit (psword); result = testUpper(psword) && testLower(psword) && testDigit(psword) && (length>=6); return result; } /**************************************************** Function testUpper is used to verify at least 1 uppercase letter is used in the user's password. *****************************************************/ bool testUpper (char psword []) { int length = strlen(psword); int count; for (count = 0; count < length; count++) { if (!isupper (psword[count])) return false; } return true; } /**************************************************** Function testLower is used to verify at least 1 lowercase letter is used in the user's password. *****************************************************/ bool testLower (char psword []) { int length = strlen(psword); int count; for (count = 0; count < length; count++) { if (!islower (psword[count])) return false; } return true; } /**************************************************** Function testDigit is used to verify at least 1 digit is used in the user's password. *****************************************************/ bool testDigit (char psword []) { int length = strlen(psword); int count; for (count = 0; count < length; count++) { if (!isdigit (psword[count])) return false; } return true; }


Can anyone help me out?
Ok, I have it solved. I got some help on another board. Changed the !isupper and the likes to issupper and tested true instead of false. This fixed my problem. If anyone needs me to post my results just reply here. Thanks.
May I note that your "Congratulatory message if passoword is valid" will only show if the password is entered correctly on the very first go... Just remove the if and put the statement on it's own underneith the while loop before the program exits.

Also you don't need to call all the functions in pswordVerify(...), just remove them and leave but leave the function calls in the variable assignment.
Last edited on
Ok thanks for the advice!
Topic archived. No new replies allowed.