help with assignment

i have no idea how do i even form this program let alone make it. My assignment entries will close in 3 hours and i need this finished asap. Hope i get help here.

Write a program that prompts the user to enter a password and then the program
validates the strength of the password based on the following rules:
a. The password must be between 8 and 32 characters.
b. The password must have at least one upper-case letter.
c. The password must have at least one digit (0-9).
d. The password must have at least one of the following special characters: $, *, ^,
&, #, _, ?.
In case the password does not follow the rules, the program must keep prompting the
user to enter a valid password.
Note: you cannot use the cctype library.





thats what i have done so far(basically nothing)

#include <iostream>
#include<string>
using namespace std;

int main()
{
string pass;
cout << "Enter a strong password: ";
cin >> pass;
int i = 0;
while (i != 0) {
if (pass.length() < 8 || pass.length() > 32) {
cout << "the password is too long or too small ";

}

else if( )
}






Perhaps something like:

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
#include <iostream>
#include <string>
#include <cstring>
using namespace std;

int main()
{
	const char* const punct {"$*^&#_?."};
	bool good {};

	do {
		string pass;

		cout << "Enter a strong password: ";
		cin >> pass;

		if ((good = pass.size() >= 8 && pass.size() <= 32)) {
			size_t up {};
			size_t dig {};
			size_t pun {};

			for (char ch : pass) {
				up += (ch >= 'A' && ch <= 'Z');
				dig += (ch >= '0' && ch <= '9');
				pun += strchr(punct, ch) != NULL;
			}

			good &= up && dig && pun;
		}
	} while (cout << (good ? "Password OK\n" : "Bad password\n") && !good);
}

Last edited on
yes, it worked,thank you so much. I have never used the cstring library though. Is there a way for it to be done with just iostream and string libraries?
[See other post]
Topic archived. No new replies allowed.