-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfun_load.cpp
More file actions
282 lines (273 loc) · 6.37 KB
/
fun_load.cpp
File metadata and controls
282 lines (273 loc) · 6.37 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
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
#include <iostream>
#include <fstream>
#include <map>
#include "sleep_cls.hpp"
#include "class_student.hpp"
#include "password.hpp"
#include "md5.hpp"
using namespace std;
Password ps;
fstream key;
MySleepCls Koishi;
map<string, string> login;
map<string, string>::iterator key_it;
int Student::welcome()
{
if (check_isfile_empty(KEY))
{
cout << "用户密码存储文件信息缺失,即将被迫回档,重新注册!\n***您可能会失去已有数据***\n按任意键继续... ";
Koishi.my_getch();
Koishi.my_cls();
re_gister(true);
return 0;
}
else
{
key.close();
cout << "请选择:登录已有账户(1)或创建新账户(2):\n";
while (1)
{
cin >> tmp;
if (tmp == "1")
break;
else if (tmp == "2")
{
re_gister(false);
return 0;
}
else
continue;
}
lo_ad();
return 1;
}
}
void Student::welcome2()
{
for (char *i = weltxt3; *i != '\000'; *i++)
{
putchar(*i);
Koishi.my_sleep(8);
}
Koishi.my_getch();
re_gister(true);
return;
}
void Student::re_gister(bool n_ew)
{
if (n_ew)
{
key.open(KEY, ios::out | ios::trunc);
key.close();
if (!check_file(KEY))
{
cout << "\n创建用户配置文件失败!\n按任意键返回...";
Koishi.my_getch();
return;
}
}
else if (!key_load())
{
Koishi.my_getch();
return;
}
while (1)
{
cout << "请创建您的的用户名(技术所限,请不要带空格):\n";
cin >> ID;
cin.ignore();
if (login.find(ID) != login.end())
{
cout << "该用户名已存在,请重新选择另一个用户名(1)或者修改登录密码(2)";
cin >> tmp;
if (tmp == "2")
{
key_it = login.find(ID);
cout << "请输入旧密码:\n";
while (1)
{
do
{
ps.key_start();
p_password = ps.Final_password;
} while (p_password == "\000");
password = MD5(p_password).toStr();
if (password == key_it->second)
{
cout << "\n请输入新密码:(请不要带空格)\n";
break;
}
else
{
cout << "\n密码错误!请重试: \n";
continue;
}
}
do
{
ps.key_start();
password = ps.Final_password;
} while (password == "\000");
password = MD5(ps.Final_password).toStr();
key_it->second = password;
if (!key_save())
{
Koishi.my_getch();
return;
}
cout << "\n修改密码成功!即将返回初始界面!\n 按任意键继续...";
Koishi.my_getch();
Koishi.my_cls();
return;
}
else
continue;
}
else
{
cout << "请为您的账户创建一个密码(请不要带空格)\n";
ps.key_start();
password = MD5(ps.Final_password).toStr();
login.insert({ID, password});
if (!key_save())
{
Koishi.my_getch();
return;
}
Koishi.my_cls();
for (int i = 3; i > 0; i--)
{
cout << "\t\t\t账户已创建完成,请登录。\n";
cout << "\t\t\t" << i << "秒后返回到主页面……" << endl;
Koishi.my_sleep(1000);
Koishi.my_cls();
}
return;
}
}
}
void Student::lo_ad()
{
if (!key_load())
{
Koishi.my_getch();
return;
}
for (char *i = weltxt1; *i != '\000'; *i++)
{
putchar(*i);
Koishi.my_sleep(8);
}
while (1)
{
do
{
cin >> ID;
cin.ignore();
} while (ID == "\000");
key_it = login.find(ID);
if (key_it == login.end())
{
cout << "用户名不存在!请重新输入: \n";
continue;
}
else
break;
}
for (char *i = weltxt2; *i != '\000'; *i++)
{
putchar(*i);
Koishi.my_sleep(8);
}
while (1)
{
do
{
ps.key_start();
password = ps.Final_password;
} while (password == "\000");
password = MD5(ps.Final_password).toStr();
if (password == key_it->second)
break;
else
{
cout << "\n密码错误!请重新输入:\n";
continue;
}
}
Koishi.my_cls();
cout << "\t\t\t登陆成功!\n";
cout << "\t\t\t按任意键进入系统\n";
Koishi.my_getch();
Koishi.my_cls();
dat_name = ID + ".dat";
return;
}
bool Student::key_load()
{
bool r_key_load = true;
key.open(KEY, ios::in);
do
{
if (!key.good())
{
cout << "用户配置文件打开失败,请重试!\n按任意键返回...\n";
r_key_load = false;
break;
}
while (key >> a >> b)
login.insert({a, b});
} while (0);
key.close();
return r_key_load;
}
bool Student::key_save()
{
bool r_key_save = true;
key.open(KEY, ios::out);
do
{
if (!key.good())
{
r_key_save = false;
cout << "密码保存失败,请重试!\n按任意键返回...\n";
break;
}
for (key_it = login.begin(); key_it != login.end(); key_it++)
{
key << key_it->first << " ";
key << key_it->second << '\n';
}
} while (0);
key.close();
return r_key_save;
}
bool Student::check_file(string file_name)
{
fstream fs;
bool r;
fs.open(file_name, ios::in);
if (fs.good())
r = true;
else
r = false;
fs.close();
return r;
}
bool Student::check_isfile_empty(string file_name)
{
int n = 0;
fstream fs;
bool r;
fs.open(file_name, ios::in);
while (getline(fs, tmp))
{
n++;
}
fs.close();
if (n == 0)
r = true;
else
r = false;
return r;
}