-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.cpp
488 lines (487 loc) · 18 KB
/
project.cpp
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
#include<iostream>
#include<windows.h>
#include<string>
#include<fstream>
#include<conio.h>
using namespace std;
class login_system
{
void waiting()
{
for(int i = 0; i < 10; i++)
{
Sleep(200);
cout<<"..";
}
}
private:
string fname, password, name, pass, date, month, year, email, number;
public:
void homepage();
void menu();
void details();
void modify();
void change_password();
void delete_account();
void exit();
};
void login_system::homepage()
{
system("cls");
cout<<"\n\t ____________________________________________________________________________________________"<<endl;
cout<<"\t | \t\t\t\t\t |";
cout<<"\n\t |\t\t\t CREATE, LOGIN & AUTHENTICATION |"<<endl;
cout<<"\t | \t\t\t\t\t |";
cout<<"\n\t |___________________________________________________________________________________________|"<<endl<<endl<<endl;
cout<<"\n\t\t\t\t\t ______________________________________\n";
cout<<"\t\t\t\t\t| |";
cout<<"\n\t\t\t\t\t| HOMEPAGE |";
cout<<"\n\t\t\t\t\t|______________________________________|";
cout<<"\n\t\t\t\t\t| |";
cout<<"\n\t\t\t\t\t|Kindly select an option below: |";
cout<<"\n\t\t\t\t\t|1. Create Account |";
cout<<"\n\t\t\t\t\t|2. Login |";
cout<<"\n\t\t\t\t\t|3. List of All Accounts |";
cout<<"\n\t\t\t\t\t|4. Search Account By Name |";
cout<<"\n\t\t\t\t\t|5. Exit |"<<endl;
cout<<"\t\t\t\t\t|______________________________________|"<<endl<<endl;
char x;
cout<<"\t\t\t\t\t-> ";
cin>>x;
if(x == '1')
{
system("cls");
cout<<"\n\t\t\t\t ________________________________________\n";
cout<<"\t\t\t\t| |";
cout<<"\n\t\t\t\t| Create Account |"<<endl;
cout<<"\t\t\t\t|________________________________________|"<<endl<<endl;
cout<<"\t\t\t\t\tEnter User_Name: "<<endl<<"\t\t\t\t\t";
cin>>fname;
cout<<endl<<"\t\t\t\t\tEnter your Date of Birth-"<<endl<<"\t\t\t\t\tDay : ";
cin>>date;
cout<<"\t\t\t\t\tMonth : ";
cin>>month;
cout<<"\t\t\t\t\tYear : ";
cin>>year;
cout<<endl<<"\t\t\t\t\tEnter your Contact Details: "<<endl<<"\t\t\t\t\tPhone Number : ";
cin>>number;
cout<<endl<<"\t\t\t\t\tEnter Email Address: "<<endl<<"\t\t\t\t\t";
cin>>email;
cout<<endl<<"\t\t\t\t\tEnter password: "<<endl<<"\t\t\t\t\t";
char ch;
password = "";
ch = _getch();
while (ch != 13)
{
password.push_back(ch);
cout << '*';
ch = _getch();
}
fstream file;
file.open("files", ios::app | ios::out);
if(!file)
{
cout<<"\t\t\t\t\tRegistration failed"<<endl<<"Try again later"<<endl;
}
else
{
file<<fname<<" "<<password<<" "<<number<<" "<<email<<" "<<date<<" "<<month<<" "<<year<<"\n";
cout<<"\n\n\t\t\t\t\tAccount Created Successfully."<<endl<<"\n\t\t\t\t\t";
file.close();
}
system("pause");
homepage();
}
else if(x == '2')
{
system("cls");
cout<<"\n\t\t\t\t\t ______________________________________\n";
cout<<"\t\t\t\t\t| |";
cout<<"\n\t\t\t\t\t| LOGIN PAGE |";
cout<<"\n\t\t\t\t\t|______________________________________|"<<endl<<endl;
fstream file;
file.open("files", ios::in);
if(!file)
{
cout<<"\t\t\t\t\t\tError! File not found"<<endl;
file.close();
cout<<"\n\t\t\t\t\t\t";
system("pause");
file.close();
homepage();
}
else
{
char ch;
name = "";
pass = "";
int flag = 0;
cout<<"\t\t\t\t\tEnter User_Name : ";
cin>>name;
cout<<"\t\t\t\t\tEnter Password : ";
ch = _getch();
while(ch != 13)
{
pass.push_back(ch);
cout<<'*';
ch = _getch();
}
file>>fname>>password>>number>>email>>date>>month>>year;
while(!file.eof())
{
if(name == fname && pass == password)
{
flag = 1;
break;
}
file>>fname>>password>>number>>email>>date>>month>>year;
}
cout<<"\n\t\t\t\t\tVerifying User Data"<<endl<<"\t\t\t\t\t";
waiting();
if(flag == 1)
{
cout<<endl<<endl<<"\t\t\t\t\tLogin Successful";
file.close();
Sleep(789);
menu();
}
else if(flag == 0)
{
cout<<endl<<endl<<"\t\t\t\t\tNo account exists with given credentials."<<endl;
cout<<"\n\t\t\t\t\t";
system("pause");
file.close();
homepage();
}
}
}
else if(x == '3')
{
int x = 1;
system("cls");
cout<<"\n\t\t\t\t ______________________________________________"<<endl;
cout<<"\t\t\t\t| |";
cout<<"\n\t\t\t\t| LIST OF ALL ACCOUNTS |"<<endl;
cout<<"\t\t\t\t|______________________________________________|"<<endl<<endl;
fstream file;
file.open("files", ios::in);
if(!file)
{
cout<<"\t\t\t\t\t Error! File not found"<<endl;
}
else
{
file>>fname>>password>>number>>email>>date>>month>>year;
while(!file.eof())
{
Sleep(66);
cout<<"\t\t\t\t\t\t ______________"<<endl;
cout<<"\t\t\t\t\t\t| |"<<endl;
cout<<"\t\t\t\t\t\t| ACCOUNT "<<x++<<" |"<<endl;
cout<<"\t\t\t\t\t\t|______________|"<<endl;
cout<<endl<<"\t\t\t\t\t 1. User_name = "<<fname<<endl;
cout<<"\t\t\t\t\t 2. Contact = "<<number<<endl;
cout<<"\t\t\t\t\t 3. Email = "<<email<<endl;
cout<<"\t\t\t\t\t 4. Date of Birth = "<<date<<"/"<<month<<"/"<<year<<endl;
cout<<"\t\t\t\t\t ------------------------------------"<<endl<<endl;
file>>fname>>password>>number>>email>>date>>month>>year;
}
cout<<"\t\t\t\t\t Reached at end of the File"<<endl;
}
file.close();
cout<<"\t\t\t\t\t ";
system("pause");
homepage();
}
else if(x == '4')
{
system("cls");
cout<<"\n\t\t\t\t ___________________________________________\n";
cout<<"\t\t\t\t| |";
cout<<"\n\t\t\t\t| SEARCH ACCOUNT |"<<endl;
cout<<"\t\t\t\t|___________________________________________|"<<endl<<endl;
cout<<"\t\t\t\t\tEnter User_Name: ";
cin>>name;
int found = 0;
fstream file;
file.open("files", ios::in);
file>>fname>>password>>number>>email>>date>>month>>year;
while(!file.eof())
{
if(name == fname)
{
Sleep(66);
cout<<endl<<"\t\t\t\t\t1. User_Name = "<<fname<<endl;
cout<<"\t\t\t\t\t2. Email = "<<email<<endl;
cout<<"\t\t\t\t\t3. Contact = "<<number<<endl;
cout<<"\t\t\t\t\t4. Date of Birth = "<<date<<"/"<<month<<"/"<<year<<endl<<endl;
cout<<"\t\t\t\t\t------------------------------------"<<endl<<endl;
found++;
}
file>>fname>>password>>number>>email>>date>>month>>year;
}
if(found == 0)
{
cout<<endl<<"\t\t\t\t\tNo account exist with ["<<name<<"] username ."<<endl<<endl;
}
file.close();
cout<<"\t\t\t\t\t";
system("pause");
homepage();
}
else if(x == '5')
{
_exit(0);
}
else
{
cout<<"\t\t\t\t\tInvalid Parameter, Try Again.";
Sleep(636);
homepage();
}
}
void login_system::menu()
{
system("cls");
cout<<"\n\t\t\t\t __________________________________________________\n";
cout<<"\t\t\t\t| |";
cout<<"\n\t\t\t\t| ACCOUNT MANAGMENT |"<<endl;
cout<<"\t\t\t\t|__________________________________________________|"<<endl<<endl<<endl;
cout<<"\t\t\t\t\tKindly select an option below:"<<endl<<endl;
cout<<"\t\t\t\t\t1. Account Details"<<endl<<endl;
cout<<"\t\t\t\t\t2. Modify Account"<<endl<<endl;
cout<<"\t\t\t\t\t3. Change Password"<<endl<<endl;
cout<<"\t\t\t\t\t4. Delete Account"<<endl<<endl;
cout<<"\t\t\t\t\t5. Logout"<<endl;
char option;
cout<<endl<<"\t\t\t\t\t-> ";
cin>>option;
switch(option)
{
case '1':
details();
break;
case '2':
modify();
break;
case '3':
change_password();
case '4':
delete_account();
case '5':
{
cout<<"\n\t\t\t\t\tLogging Out . . ."<<endl<<"\t\t\t\t\t";
waiting();
homepage();
}
default:
cout<<"\t\t\t\t\tInvalid Option\n\t\t\t\t\tTry Again."<<endl;
Sleep(636);
menu();
}
}
void login_system::details()
{
system("cls");
cout<<"\n\t\t\t\t ___________________________________________\n";
cout<<"\t\t\t\t| |";
cout<<"\n\t\t\t\t| ACCOUNT DETAILS |"<<endl;
cout<<"\t\t\t\t|___________________________________________|"<<endl<<endl;
fstream file;
file.open("files", ios::in);
file>>fname>>password>>number>>email>>date>>month>>year;
while(!file.eof())
{
if(name == fname && password == pass)
{
Sleep(66);
cout<<endl<<"\t\t\t\t\t1. User_Name = "<<fname<<endl<<endl;
Sleep(66);
cout<<"\t\t\t\t\t2. Email = "<<email<<endl<<endl;
Sleep(66);
cout<<"\t\t\t\t\t3. Contact = "<<number<<endl<<endl;
Sleep(66);
cout<<"\t\t\t\t\t4. Date of Birth = "<<date<<"/"<<month<<"/"<<year<<endl<<endl;
Sleep(66);
cout<<"\t\t\t\t\t5. Account Password = "<<password<<endl<<endl;
break;
}
file>>fname>>password>>number>>email>>date>>month>>year;
}
file.close();
cout<<"\t\t\t\t\t";
system("pause");
menu();
}
void login_system::modify()
{
system("cls");
cout<<"\n\t\t\t\t ___________________________________________\n";
cout<<"\t\t\t\t| |";
cout<<"\n\t\t\t\t| MODIFY ACCOUNT |"<<endl;
cout<<"\t\t\t\t|___________________________________________|"<<endl<<endl;
fstream file, file1;
file.open("files", ios::in);
file1.open("modify", ios::app | ios::out);
file>>fname>>password>>number>>email>>date>>month>>year;
while(!file.eof())
{
if(name == fname && pass == password)
{
cout<<"\t\t\t\t\tEnter User_Name: "<<endl<<"\t\t\t\t\t";
cin>>fname;
cout<<endl<<"\t\t\t\t\tEnter your Date of Birth- "<<endl<<"\t\t\t\t\tDay : ";
cin>>date;
cout<<"\t\t\t\t\tMonth : ";
cin>>month;
cout<<"\t\t\t\t\tYear : ";
cin>>year;
cout<<endl<<"\t\t\t\t\tEnter your Contact Details: "<<endl<<"\t\t\t\t\tPhone Number : ";
cin>>number;
cout<<endl<<"\t\t\t\t\tEnter Email Address: "<<endl<<"\t\t\t\t\t";
cin>>email;
file1<<fname<<" "<<password<<" "<<number<<" "<<email<<" "<<date<<" "<<month<<" "<<year<<"\n";
}
else
{
file1<<fname<<" "<<password<<" "<<number<<" "<<email<<" "<<date<<" "<<month<<" "<<year<<"\n";
}
file>>fname>>password>>number>>email>>date>>month>>year;
}
cout<<endl<<"\t\t\t\t\tSaving new details, Please wait . . ."<<endl<<"\t\t\t\t\t";
waiting();
file.close();
file1.close();
remove("files");
rename("modify", "files");
cout<<endl<<"\n\t\t\t\t\tAccount Details Saved Successfully."<<endl;
cout<<"\t\t\t\t\tChanges will be shown after Re-login."<<endl<<"\n\t\t\t\t\t";
system("pause");
menu();
}
void login_system::change_password()
{
system("cls");
cout<<"\n\t\t\t\t ___________________________________________\n";
cout<<"\t\t\t\t| |";
cout<<"\n\t\t\t\t| CHANGE PASSWORD |"<<endl;
cout<<"\t\t\t\t|___________________________________________|"<<endl<<endl;
string oldpass, newpass, confirmpass;
cout<<"\t\t\t\t\tEnter your Old Password: ";
cin>>oldpass;
if(oldpass == pass)
{
cout<<endl<<"\t\t\t\t\tEnter New Password: ";
cin>>newpass;
if(newpass == oldpass)
{
cout<<endl<<"\t\t\t\t\tOld and New Password can't be same.";
}
else
{
cout<<endl<<"\t\t\t\t\tConfirm New Password: ";
cin>>confirmpass;
if(confirmpass != newpass)
{
cout<<endl<<"\t\t\t\t\tError! Password mismatch."<<endl<<"\t\t\t\t\tPlease try again.";
Sleep(636);
change_password();
}
else
{
fstream file, file1;
file.open("files", ios::in);
file1.open("modify", ios::app | ios::out);
file>>fname>>password>>number>>email>>date>>month>>year;
while(!file.eof())
{
if(name == fname && pass == oldpass)
{
file1<<fname<<" "<<newpass<<" "<<number<<" "<<email<<" "<<date<<" "<<month<<" "<<year<<"\n";
}
else
{
file1<<fname<<" "<<password<<" "<<number<<" "<<email<<" "<<date<<" "<<month<<" "<<year<<"\n";
}
file>>fname>>password>>number>>email>>date>>month>>year;
}
cout<<endl<<"\t\t\t\t\tChanging Password, Please wait . . ."<<endl<<"\t\t\t\t\t";
waiting();
cout<<endl<<"\n\t\t\t\t\tPassword changed successfully."<<endl;
cout<<endl<<"\t\t\t\t\tChanges will be shown after Re-login."<<endl;
file.close();
file1.close();
remove("files");
rename("modify", "files");
}
}
}
else
{
cout<<endl<<"\t\t\t\t\tError! Wrong Password"<<endl;
}
cout<<endl<<"\t\t\t\t\t";
system("pause");
menu();
}
void login_system::delete_account()
{
system("cls");
cout<<"\n\t\t\t\t ___________________________________________\n";
cout<<"\t\t\t\t| |";
cout<<"\n\t\t\t\t| DELETE ACCOUNT |"<<endl;
cout<<"\t\t\t\t|___________________________________________|"<<endl<<endl;
cout<<"\t\t\t\t\tAre you sure want to delete account ?"<<endl;
cout<<"\t\t\t\t\tThis action can't be undone!"<<endl;
cout<<"\t\t\t\t\tY/N: ";
char x;
cin>>x;
if(x == 'y' || x == 'Y')
{
fstream file, file1;
file.open("files", ios::in);
file1.open("modify", ios::app | ios::out);
file>>fname>>password>>number>>email>>date>>month>>year;
while(!file.eof())
{
if(name == fname && pass == password)
{
// file>>fname>>password>>number>>email>>date>>month>>year;
}
else
{
file1<<fname<<" "<<password<<" "<<number<<" "<<email<<" "<<date<<" "<<month<<" "<<year<<"\n";
}
file>>fname>>password>>number>>email>>date>>month>>year;
}
cout<<endl<<"\t\t\t\t\tDeleting Account . . ."<<endl<<"\t\t\t\t\t";
waiting();
cout<<endl<<"\n\t\t\t\t\tAccount Deleted Successfully."<<endl;
cout<<endl<<"\t\t\t\t\tLogging you out . . ."<<endl<<"\t\t\t\t\t";
waiting();
file.close();
file1.close();
remove("files");
rename("modify", "files");
homepage();
}
else if(x == 'N' || x == 'n')
{
cout<<endl<<"\t\t\t\t\tTaking you back to Main Menu"<<endl<<"\t\t\t\t\t";
waiting();
Sleep(636);
menu();
}
else
{
cout<<"\t\t\t\t\tPlease select a valid option."<<endl;
system("pause");
delete_account();
}
}
int main()
{
login_system x;
x.homepage();
return 0;
}