making a Password with string, do,while, if and else

Hey guys first let me tell you that i am taking class of basic programming and i am a little slow on learn the codes. Okay my question is how to make a loop stop and after that how to clear it completely so that the user have to confirm the password.

Now i was able to do the first part(i even added some additional strings just in case) but i got stuck when this part(if (Input == num & mayor & minor & symbols) didn't want to run and also on the second part is receiving errors on the variable bool that it didn't accept the (otropw). I use (otropw)to save the password.

Also correct me if i am wrong but (getpassword) stands for getting the save password?

Can you guys please 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
//first part
  string Input;
	string B(int = 1);
	string C;
	string num = "1234567890";
	string mayor = "QWERTYUIOPASDFGHJKLZXCVBNM";
	string minor = "qwertyuiopasdfghjklzxcvbnm";
	string symbols = "!@#$%^&*()";
	string password;
	bool insert = false;

	cout << "El password debe contener:";
	cout << "De 6 a 12 char\n";
	cout << "Algun numero\n";
	cout << "Una mayuscula\n";
	cout << "Una minuscula\n";
	cout << "Un simbolo\n";
	cout << "Sin espacio\n";


	string otropw;

	do  //primera parte
	{
		getline(cin, Input);

		//length

		if (Input.length() >= 6)
		{
			cout << " ";

		}

		else
		{

			cout << "Faltan mas letras\n";


		}

		//num


		if (Input.find_first_of(num) != string::npos)
		{
			cout << " ";
		}

		else
		{

			cout << "Falta numero\n";

		}

		//Symbols

		if (Input.find_first_of(symbols) != string::npos)
		{
			cout << " ";
		}

		else
		{

			cout << "Falta symbolo\n";

		}

		//mayor
		if (Input.find_first_of(mayor) != string::npos)
		{
			cout << " ";
		}

		else
		{

			cout << "Falta Mayuscula\n";

		}


		//minor

		if (Input.find_first_of(minor) != string::npos)
		{
			cout << " ";
		}

		else
		{

			cout << " Falta Minuscula\n";

		}


		if (Input.find(" ") != string::npos)
		{
			cout << " No hagas espacio!";
		}

		if (Input == num & mayor & minor & symbols) //this is how is going to break 
		{
			break;
			otropw = Input;
			system("pause");
			system("cls");
			
			
		}
	} //final de la primera parte



	bool getpassword(otropw);//segunda parte
	     
	int input = 1;
	
	while (input <=3);   
	{
		
			string password;
			cout << " confirma tu password: ";
			getline(cin, password);
			input++;     // This makes you have three tries

			if (password == otropw) return true; // this is the actual password

			cout << "Invalid. " << endl;

		
	

     }
	
	return false;

	if (input != getPassword(otropw)) return 0; //se supone que termine el programa

	
	
system("pause");


Somehow I don't understand fully what you want to do.
A simple demo to enter and confirm a password.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main()
{
  string original_pw, confirm_pw;
  do
  {
    cout << "Please enter password: ";
    cin >> original_pw; // assume no spaces allowed
    cout << "\nPlease confirm password: ";
    cin >> confirm_pw;
    if (original_pw != confirm_pw)
      cout << "\nPasswords don't match.\n";
    else
      cout << "\nOK\n";
  }while (original_pw != confirm_pw);
}
Hello Redstar6,

The code looks like a nice start, but it is missing some parts like the header files, main and the function "getPassword".

Also correct me if i am wrong but (getpassword) stands for getting the save password?

Most likely no. "getPassword(otropw)" looks like a function that you have written, but I am not sure what the code of this function is or what you are trying to do.

Line 119 is a either part way to a prototype or a function call. I think you are trying to write a prototype, but missing some information in side the ().

I will have to see if I can figure out a working program to test what you have. Not sure if I will get it right.

Andy
One mistake i found is below:

1
2
3
4
5
6
7
8
9
if (Input == num & mayor & minor & symbols) //this is how is going to break 
		{
			break;
			otropw = Input;  
			system("pause");
			system("cls");
			
			
		}

break statement: stops the loop,ignoring after-it lines.
@ BearDone

And you missed the bigger problem with the if condition? Also look at what is being compared.

Andy

Edit:
Last edited on
ok let me be clear

the first part is a loop that i wanted to stop and i finally did


if (Input == num && Input == mayor && Input == minor && Input == symbols)
{

otropw = Input;
system("pause");
system("cls");


}

yay!!

now the second part is when i want to confirm the password and have 3 tries
(otropw is where the saved password is) and this is the part that i am stuck now

string otropw,confirm_otropw;

string what_you_think_is_pw;


do
{
cout << "Please enter password: ";
cin >> what_you_think_is_pw;

cout << "\nPlease confirm password: ";
cin >> confirm_pw ++;


if (original_pw != confirm_pw)
cout << "\nPasswords don't match.\n";
else
cout << "\nOK\n";
} while ( what_you_think_is_pw != confirm_pw);


Hello Redstar6,

Sorry for the delay, I have been sick on and off for the since the first of the month.

You have made changes That you say work for you, so you should post the new code to show what you have done.

I fine this line questionable: if (Input == num && Input == mayor && Input == minor && Input == symbols) because I do not know what came before it.

The do/while loop looks like Thomas1965's example and should work, but it is only part of your code and out of context it is hard to say if it will work with your program.

It would be helpful if you could post the whole program because what you think is the problem may start somewhere else and that is hard to guess at.

What I came up with to test your code is completely different from what you have, so we are working in two different directions.

Hope that helps,

Andy
Registered users can post here. Sign in or register to post.