Help with program

Im trying to get a password verifier program working, i have made functions for it but, when i put in input it saves the first time but after it goes into checklength function it just goes in as a blank space.

I put some debugging things for me in there but i still can't figure out why its not working.

Thanks for the help



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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <iostream>
#include <string>
#include <iomanip>
#include <cstring>

using namespace std;

//****************************************************************************************************

void getInput(char password[]);
bool checkLength (char password[]);
bool checkCase (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];
	const int SIZE = 50;
	
	bool inputLength;
	bool inputCase; 
	bool inputLowercase; 
	bool inputDigit; 
	bool inputAlpha; 
	bool inputWhiteSpace; 

	
	getInput (input);

	cout << "pass: " << input << endl; // rafal
	 inputLength = checkLength(input);
	cout << "pass: " << input << endl; // rafal
    inputCase = checkCase(input);
	cout << "pass: " << input << endl; // rafal
	inputLowercase = checkLowercase(input);
	inputDigit = checkDigit(input);
    inputAlpha = checkAlpha(input);
	inputWhiteSpace = checkWhiteSpace(input);
	cout << "pass: " << input << endl; // rafal
	
}

//****************************************************************************************************

void getInput(char password[])
{
	cout << "********************************************************************************";
	cout << "Please enter a valid password" << endl;
	cin.getline (password,SIZE);
		
}
//***************************************************************************************************

bool checkWhiteSpace (char password[])
{
    bool iswhitespace = true;

    for (int cnt = 0; cnt < SIZE; cnt++)
    {
        if (password [cnt] == ' ')
        {
            iswhitespace = false;
			cout << "Error, password must not contain any whitespace.\n";
            break;
        }
    }

    return iswhitespace;
}

//****************************************************************************************************

bool checkLength (char password[])
{
    int numChar = 0;
    bool validlength = false;

    for (int cnt = 0; cnt < SIZE; cnt++)
    {
        if (password [cnt] = '\0')
		{
        numChar = cnt;
		break ;
		}
cout << "number cout : " << cnt << "pass " << password << endl; // rafal
    }

    if ((numChar >= 6) && (numChar <= 13))    
        validlength = true;

	if (validlength = false)
	{
		 cout << "Error, password must be at least 6 characters long.\n";
	}

    return validlength;

}

//****************************************************************************************************
bool checkLowercase(char password[])
{
	bool lower = false;
    for (int cnt = 0; cnt < SIZE; cnt++)
    {
        if (islower(password[cnt]!='\0'))
        return true;
    }
	if (lower == false)
	{
	cout << "Error, password must contain at least one lower case letter.\n";
	}
    return lower;
}
//****************************************************************************************************
bool checkCase(char password[])
{
	bool upper = false;
    for (int cnt = 0; cnt < 20; cnt++)
    {
        if (isupper(password[cnt]))
        return true;
    }
	if ( upper == false)
	{
	cout << "Error, password must contain at least one upper case letter.\n";
	}
    return upper;
}
//****************************************************************************************************
bool checkDigit(char password[])
{
	bool digit = false;
    for (int cnt = 0; cnt < 20; cnt++)
    {
        if (isdigit(password[cnt]))
        return true;
    }
	if ( digit == false)
	{
	cout << "Error, password must contain at least one digit.\n";
	}
    return digit;
}
//****************************************************************************************************

bool checkAlpha (char password[])
{
	bool Alpha = false;
	int i = 0;

	while ((password [i] != '\0') && (!Alpha))
	{
		if (!isalnum (password [i]))
			Alpha = true;
			i++;
		
	}
	if ( Alpha == false)
	{
		cout << "Error, password must contain at least one symbol that is not numeric.\n";
	}

	return Alpha;
}
[Line 86] You need to use:
if (password [cnt] == '\0')
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.
If you've fixed it then update your code to match the fix.
Another one:
1
2
[Line 97]
if (validlength = false)


Applying both fixes, and running the code does not seem to produce the same output you claim it does:
http://coliru.stacked-crooked.com/a/d0c6675d5e91d0ba
closed account (SEh54iN6)
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
Thanks a lot Terrison, i was working on it last night but i forgot to check the website. Thank you again
Topic archived. No new replies allowed.