Unknown problem?

See my 5th post. Out of characters.
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
using namespace std;
void encrypt( char [ ] );
void decrypt( char * ePtr );

int pinCorrect (int x)
{		

	if (x < 10000)
		{
			if (x > 0)
			return x;
		}
	else
	if (x == 10000)
		{
			cout << "No pin assigned\n";
			cout << "Writing '0' for none\n";
			return 0;
		}
	else
	cout << "Failed checklist\n";
	cout << "Pin is not more than 0 or not less than 10,000, invalid.\n";
	return 404;
}





int main()

{

    char usernameS[256];
	char passwordS[256];
    int pinS;
	int pinraw;
	int lors;
	int recovS; 
	char emailS[256];
	char recov1S[256];
	char recov2S[256];
	char recov3S[256];
	char recov4S[256];
	char recov5S[256];
	char password1S[256];
	char password2S[256];
	char password3S[256];
	char createdS[256];
	char providerS[256];
	char movedS[256];
	char adS[256];
	int recovL; 
	char emailL[256];
	char recov1L[256];
	char recov2L[256];
	char recov3L[256];
	char recov4L[256];
	char recov5L[256];
	char password1L[256];
	char password2L[256];
	char password3L[256];
	char createdL[256];
	char providerL[256];
	char movedL[256];
	char adL[256];
	int mpy;
	int empty;
	char masterS[256];
	char masterL[256];
	int mpstatus;
	char mastercheck[256];
	int one;
	one = 1;
cout << "Have you saved a master password yet?\n";
cout << "If not, you will need to do so to be able to load accounts.\n";
cout << "1 for yes, 2 for no: ";
cin >> mpy;
	if (mpy == 2)
		{
			cout << "\nEnter a master password you would like to use for future use of\nloading accounts: ";
			cin >> masterS;
			encrypt(masterS);
			ofstream Students("Masterpassword", ios::out);
			Students << masterS;
            Students.close();
			cout << "\nMaster password saved.\n\n\n";
			cin >> empty;
			return 0;
		}
else
cout << "Press 1 to Load an account, or 2 to save or overwrite an account: ";
cin >> lors;
	if (lors == 1)
		{
			char user[20];
			char usernameL[20];
			char passwordL[20];
			int pinL;
			ifstream Students("Masterpassword");
			Students >> masterL;// >> mpstatus;
			//if (mpstatus != 1)
			//	{
			//		cout << "\nNo masterpassword file found. Please (re)create one\n\n\n.";
			//		cin >> empty;
			//		return 0;
			//	}
			cout << masterL << endl;
			cout << "What is the master password? ";
			cin >> mastercheck;
			decrypt(masterL);
			if (masterL == mastercheck)
				{
					cout << "\nWhat is the username of the account you would like to load? ";
					cin >> user;
					ifstream Students(user);
					Students >> usernameL >> passwordL >> pinL >> recovL >> emailL >> recov1L >> recov2L >> recov3L >> recov4L >> recov5L >> password1L >> password2L >> password3L >> createdL >> providerL >> movedL >> adL;
					decrypt(passwordL);
					decrypt(emailL);
					decrypt(recov1L);
					decrypt(recov2L);
					decrypt(recov3L);
					decrypt(recov4L);
					decrypt(recov5L);
					decrypt(password1L);
					decrypt(password2L);
					decrypt(password3L);
					decrypt(createdL);
					decrypt(providerL);
					decrypt(movedL);
					decrypt(adL);
					if (recovL == 1)
						{
							cout << "\n\n\nUsername: " << usernameL;
							cout << "\nPassword: " << passwordL;
							cout << "\nPin: " << pinL;
							cout << "\nAnswer to recovery question 1: " << recov1L;
							cout << "\nAnswer to recovery question 2: " << recov2L;
							cout << "\nAnswer to recovery question 3: " << recov3L;
							cout << "\nAnswer to recovery question 4: " << recov4L;
							cout << "\nAnswer to recovery question 5: " << recov5L;
							cout << "\nThe earliest password you can remember: " << password1L;
							cout << "\nThe next password you can remember: " << password2L;
							cout << "\nThe next password you can remember: " << password3L;
							cout << "\nAccount creation date: " << createdL;
							cout << "\nInternet provider created with: " << providerL;
							cout << "\nDate you have moved: " << movedL;
							cout << "\nAdditional Details: " << adL;
							cout << "\n\n\nClose when finished\n";
							cin >> empty;
							return 0;
						}
					else
					if (recovL == 2)
						{
							cout << "\n\n\nUsername: " << usernameL;
							cout << "\nPassword: " << passwordL;
							cout << "\nPin: " << pinL;
							cout << "\n\n\nClose when finished\n";
							cin >> empty;
							return 0;
						}
					else
					return 0;

			}
			else
			cout << "\n\nIncorrect password.\n";
			cin >> empty;
			return 0;
	}
		else
		if (lors == 2)
		{
		cout << "Use _underscore_ for spaces\n";
		cout << "Username: ";
		cin >> usernameS;
		cout << "\nPassword: ";
		cin >> passwordS;
		cout << "\nPin (If none enter 10000): ";
		cin >> pinraw;
		pinS=pinCorrect(pinraw);
		if (pinS == 404)
			{
				cout << "Killing script.\n\n\n\n"; //NEEDS WORK
				cin >> empty;
				return 0;
			}		

				else		
				cout << "Does the account have recovery questions set? Enter 1 for yes and 2 for no: ";
				cin >> recovS;
				if (recovS == 1)
					{
						cout << "For the following questions, if none is set, enter 'none'\n";
						cout << "What email is registered (DO NOT INCLUDE @ SYMBOL): ";
						cin >> emailS;
						cout << "\nAnswer to recovery question 1: ";
						cin >> recov1S;
						cout << "\nAnswer to recovery question 2: ";
						cin	>> recov2S;
						cout << "\nAnswer to recovery question 3: ";
						cin >> recov3S;
						cout << "\nAnswer to recovery question 4: ";
						cin >> recov4S;
						cout << "\nAnswer to recovery question 5: ";
						cin >> recov5S;
						cout << "\nThe earliest password you can remember: ";
						cin >> password1S;
						cout << "\nThe next password you can remember: ";
						cin >> password2S;
						cout << "\nThe next password you can remember: ";
						cin >> password3S;
						cout << "\nAccount creation date: ";
						cin >> createdS;
						cout << "\nInternet provider created with: ";
						cin >> providerS;
						cout << "\nDate you have moved: ";
						cin >> movedS;
						cout << "\nAdditional Details: ";
						cin >> adS;
						encrypt(passwordS);
						encrypt(emailS);
						encrypt(recov1S);
						encrypt(recov2S);
						encrypt(recov3S);
						encrypt(recov4S);
						encrypt(recov5S);
						encrypt(password1S);
						encrypt(password2S);
						encrypt(password3S);
						encrypt(createdS);
						encrypt(providerS);
						encrypt(movedS);
						encrypt(adS);				
						ofstream Students(usernameS, ios::out);
						Students << usernameS << "\n" << passwordS << "\n" << pinS << "\n" << recovS << "\n" << emailS << "\n" << recov1S << "\n" << recov2S << "\n" << recov3S << "\n" << recov4S << "\n" << recov5S << "\n"<< password1S << "\n" << password2S << "\n" << password3S << "\n" << createdS << "\n" << providerS << "\n" << movedS << "\n" << adS;
					}
				else
				if (recovS != 2)
					{
						return 0;
					}
				else
				if (recovS == 2)
					{
						encrypt(passwordS);
						ofstream Students(usernameS, ios::out);
						Students << usernameS << "\n" << passwordS << "\n" << pinS << "\n" << recovS;
					}
		}

		
	}
	
	
		
void encrypt (char e[] ) 
	{
		for( int i=0; e[i] != '\0'; ++i ) ++e[i];
	}

void decrypt( char * ePtr )
	{
		for( ; * ePtr != '\0'; ++ ePtr ) --(* ePtr);
	}

		

Sorry for such a big post, but I have no idea where the problem is.
Last edited on
Bump
maybe your file is readonly?
It creates the file itself, and I checked and the check box was unticked.
He's not closing the file properly.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cin >> mpy;
	if (mpy == 2)
		{
			cout << "\nEnter a master password you would like to use for future use of\nloading accounts: ";
			cin >> masterS;
			encrypt(masterS);
			ofstream Students("Masterpassword", ios::out);
			Students << masterS;
                        //NEED TO CLOSE THE FILE NOW WE HAVE FINISHED WRITING TO IT
                        Students.close();

			cout << "\nMaster password saved.\n\n\n";
			cin >> empty;
			return 0;
		}
Nice catch, problem solved :)
Thanks
Ok new problem, I believe it's here:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
			ifstream Students("Masterpassword");
			Students >> masterL;// >> mpstatus;
			//if (mpstatus != 1)
			//	{
			//		cout << "\nNo masterpassword file found. Please (re)create one\n\n\n.";
			//		cin >> empty;
			//		return 0;
			//	}
			cout << masterL << endl;
			cout << "What is the master password? ";
			cin >> mastercheck;
			decrypt(masterL);
			if (masterL == mastercheck)// <<< Problem?#####
				{

Is this a proper way to check if the password entered is the same as the master password? I set it to say the password right before I entered it so I know it's not a problem with encryption/decryption or mistyping. When I know I entered the correct password, it skips the bracket and goes all the way down to the "else" which outputs incorrect password.
Heres what I put to save the master password:
Have you saved a master password yet?
If not, you will need to do so to be able to load accounts.
1 for yes, 2 for no: 2

Enter a master password you would like to use for future use of
loading accounts: hi

Master password saved.


Then when I load an account, it says:
Have you saved a master password yet?
If not, you will need to do so to be able to load accounts.
1 for yes, 2 for no: 1
Press 1 to Load an account, or 2 to save or overwrite an account: 1
hi (((<-Thats the password)))
What is the master password? hi


Incorrect password.


I updated the main post.
Yes - if (masterL == mastercheck) //problem

Both masterL and mastercheck have been declared a char arrays:
1
2
3
	
char masterS[256];
char masterL[256];


So what you are doing is comparing two pointers - not two 'strings'

As you are using char arrays - You can use the C function strcmp (stringcompare) to
compare the arrays.
1
2
3
4
5
6
			
decrypt(masterL); 	   	   	  
 if ( ! strcmp(masterL,mastercheck))
    {
        cout << "\nWhat is the username of the account you would like to load? ";


You may need to #include <cstring>
Last edited on
Thanks for all the help, one more problem down. The next one is shows off what a beginner I am. Using "char xxx" doesn't allow spaces, and when they are used, it uses them in the next input value. So how do I get around that and let the user use spaces?
1
2
3
//		cin >> masterS;
		cin.ignore( 1024, '\n' );
		cin.getline(masterS, 255);
Topic archived. No new replies allowed.