-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmini-database.cpp
More file actions
215 lines (197 loc) · 5.31 KB
/
Copy pathmini-database.cpp
File metadata and controls
215 lines (197 loc) · 5.31 KB
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
#include <iostream>
#include <fstream>
#include <string.h>
#include <climits>
#include <windows.h>
using namespace std;
class Base{
public:
void crefil()
{
system("cls");
string fname,message;
cout<<"\n Enter file name: ";
cin>>fname;
cin.ignore(INT_MAX,'\n');
cout<<"Enter the file data: ";
getline(cin,message);
ofstream fout(fname);
fout<<message;
fout.close();
}
void reafil()
{
system("cls");
string fname,str;
cout<<"\nEnter file name: ";
cin>>fname;
ifstream fin(fname);
while(!fin.eof())
{
fin>>str;
cout<<str<<" ";
}
cout<<"\n \n"<<endl;
fin.close();
}
void edifil()
{
system("cls");
string fname,message;
cout<<"\n Enter file name: ";
cin>>fname;
cin.ignore(INT_MAX,'\n');
cout<<"Enter the file data: ";
getline(cin,message);
ofstream fout(fname, ios::app);
fout<<"\n"<<message;
fout.close();
}
void logout()
{
system("cls");
cout<<"********************logging out********************"<<endl;
Sleep(1500);
system("cls");
}
void def(){
cout<<"\nSorry, wrong choice selected.\nEnter your choice again\n"<<endl;
Sleep(1500);
system("cls");
}
void newuse()
{
system("cls");
string useid,usepass;
cout<<"Enter the User ID: ";
cin >> useid;
cout<<"Enter the User Password: ";
cin >> usepass;
ofstream fout("login.txt", ios::app);
fout<< useid << " " << usepass<<"\n"<<endl;
fout.close();
}
void deluse()
{
system("cls");
}
};
class user : Base
{
private:
int choice;
public:
user()
{
// system("cls");
cout<<"********************Login Successful********************\n";
cout<<"1. Create New file \n2. Read existing file \n3. Edit a file \n4. Logout \n5. Exit";
cout<<"\nEnter your choice: ";
cin>>choice;
switch(choice){
case 1:
crefil();
cll();
break;
case 2:
reafil();
cll();
break;
case 3:
edifil();
cll();
break;
case 4:
logout();
break;
case 5:
terminate();
default:
def();
cll();
break;
}
}
void cll(){
user use;
}
};
class sup_user : Base
{
private:
int choice=0;
public:
sup_user()
{
cout<<"********************Super User Account activated********************\n";
cout<<"1. Create New file \n2. Read existing file \n3. Edit a file \n4. Create a new user \n5. Delete a user \n6. Logout \n7. Exit"<<endl;
cout<<"\nEnter your choice: ";
cin>>choice;
switch(choice){
case 1:
crefil();
cll();
break;
case 2:
reafil();
cll();
break;
case 3:
edifil();
cll();
break;
case 4:
newuse();
cll();
break;
case 5:
deluse();
cll();
break;
case 6:
logout();
break;
case 7:
terminate();
default:
def();
cll();
break;
}
}
void cll(){
sup_user su;
}
};
int main()
{
ifstream fin("login.txt", ios::in);
char emid[50], pass[20], str[30];
string suid="admin@gmail.com", supass="admin@123", u, p;
cout<<"Welcome User, Please enter your credentials here\n";
cout<<"Enter your email id: ";
cin>>emid;
cout<<"Enter your password: ";
cin>>pass;
if(emid==suid && pass==supass)
{
system("cls");
sup_user su;
}
else
while(fin>>u>>p)
{
if(u == emid && p == pass)
{
system("cls");
user us;
}
else
{
cout<<"Sorry, Wrong ID or Password\nPlease enter your details again"<<endl;
}
}
cout<<"\n\n";
fin.close();
main();
}