Help with Password Validation Program

I'm having some trouble with a password validation program, I have the basics taken care of but I can't figure out where to go next. The details for the program are as follows:

Create a .cpp program that verifies the strength of a password that a user is entering is strong (complex/secure) enough. In the main area of the program, prompt the user to enter a password. Then, call a function, passing into it the password that they entered.
In the function, use whatever .cpp commands or built-in functions are available to ensure:
a. The password is at least 8 characters in length.
b. The password is mixed case (upper and lower).
c. You have at least one of these valid special characters in your password:
$ ! @ % ^ & * #
The function will determine if the password is strong enough and then output the correct message. Here is a sample run and output from the program:

First Run:
Enter a password: thisis
Your password length is too short. Please choose a password that is at least 8 characters long.
Your password is not a mixed case. Please choose a password with mixed case.
You do not have a valid special character in your password. Please add at least one special character.

Second Run:
Enter a password: thisismypassword
Your password is not a mixed case. Please choose a password with mixed case.
You do not have a valid special character in your password. Please add at least one special character.

Third Run:
Enter a password: Thisismypassword
You do not have a valid special character in your password. Please add at least one special character.

Fourth Run:
Enter a password: thisis!myPassWORD
Thank you. Your password is valid

the following is the code I have written so far:

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
#include <iostream>
#include <string>

using namespace std;

int main()
{
	//Declaration Block
	char userPassword;

	//User Input Block
	cout << "Please enter your password: "; 
	cin >> userPassword;

	//Processing Block 
	if (userPassword != 8)
	{
		cout << "Your password is not long enough, please enter a password that is at least eight characters long " << endl;
	}
	else
		








	system("pause");
	return 0;
}
closed account (48T7M4Gy)
userPassword should be a string, not char.

You also need to use the reference materials and tutorials here because string has a function length() which determines how many characters in the string. So your if condition should be
if(userPassword.length() < 8) etc
Last edited on
ah ok thanks :)
However I'm still unsure on the mixed case, and valid special character fucntions for the program.
closed account (48T7M4Gy)
For Second run you need to write a loop to look at each character in the password one at a time. You then have to look at the case, upper or lower and test whether there are multiple cases.

http://www.cplusplus.com/reference/cctype/islower/

If you go there you will find there are functions for doing other checks you can incorporate in the tests.


http://www.cplusplus.com/reference/string/string/length/
Last edited on
closed account (48T7M4Gy)
Your turn now to come back with some code. Remember that userPassword[i] is the i-th character in userPassword.
Topic archived. No new replies allowed.