Problem with password verifier

Hey there everyone. I just need a push in the right direction here. This is my third week with C++, and I thought I was on a roll with this program, but now I'm just beating my head against the wall. I first used a bool function, but then realized the instructor stated to use a void function only. Since I've change that, and tweaked the function to work without returning a value, it seems to have fallen apart. Any help is appreciated. When it runs, it allows you to put in the password you desire, but then nothing else happens. It just allows you to press any key to end the program.

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
// This program is a small part of a larger program that
// verifies that the selected password follows the security
// requirements of the program. The password must contain at least
// six characters, one uppercase letter, one lowercase letter
// and one digit. If one of these requirements were not met,
// it will explaint to the user which requirement was not met.

#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;

int tryAgain;					// To know if we should try again
const int SIZE = 25;			// To allow up to 24 character in the password and \0
char password[SIZE];			// To hold password selected
int length = strlen(password);	// To get the length of the entered password

// Function prototype
void validatePassword(char password[SIZE]);

int main()
{

	// Introduction to password verifier
	cout << "Welcome. Please have your password ready." << endl;
	cout << "Your desired password must contain the following: " << endl;
	cout << "\t - At least six characters" << endl;
	cout << "\t - At least one lowercase character" << endl;
	cout << "\t - At least one uppercase character" << endl;
	cout << "\t - At least one digit" << endl << endl;
	cout << "Please enter your password . . ." << endl << endl;
	cin.getline(password, SIZE);

	// Validate the password
	void validatePassword(char password[SIZE]);

	// Run function again if the password was found to be invalid
	if (tryAgain = 0)
	{
		cin.getline(password, SIZE);
		void validatePassword(char password[SIZE]);
	}
	
	system("pause");
	return 0;
}

// ***
// Definition of function validatePassword
// This function validates the password input by the user by
// checking that it is at least 6 characters long, has at least
// one lowercase, one uppercase, and one digit.
// ***
void validatePassword(char password[SIZE])
{
	int count;
	int upperCase = 0;
	int lowerCase = 0;
	int digit = 0;

	for (count = 0; count < SIZE; count++)
	{
		if (isupper(password[count]))
			upperCase++;

		if(islower(password[count]))
			lowerCase++;

		if(isdigit(password[count]))
			digit++;
	}

	// Tell user which requirements have not been met
	if (upperCase == 0)
	{
		cout << "You must use an uppercase letter." << endl;
	}

	if (lowerCase == 0)
	{
		cout << "You must use a lowercase letter." << endl;
	}

	if (digit == 0)
	{
		cout << "You must use at least one digit." << endl;
	}

	if (strlen(password) < 6)
	{
		cout << "Your password must be at least 6 characters long." << endl;
		length = 0;
	}
	
	if (upperCase == 0 || lowerCase == 0 || digit == 0 || length == 0)
	{
		tryAgain = 0;
		cout << "Please try again." << endl;
	}
	else
		tryAgain = 1;


}
Topic archived. No new replies allowed.