-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount.c
287 lines (265 loc) · 5.71 KB
/
account.c
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
#include <stdio.h>
#include <dos.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <dos.h>
#include <time.h>
#include <conio.h>
#include <dir.h>
#include "head.h"
#include "SVGA.h"
#include "HANZI.h"
#include "mouse.h"
#include "button.h"
#include "account.h"
#include "input.h"
#include "show.h"
/**********************************************************************
功能说明:添加新的账户
参数说明:p 为要添加的账户
返回值说明:无
*********************************************************************/
void AddAccount(Account p)
{
FILE *fp, *tfp,*fmap;
int count;
char path[MAXLEN*2];
char dir[MAXLEN*2];
fp = fopen(USERFILE, "r+");
if (fp == NULL)
{
printf("can't open %s\n",USERFILE);
getch();
exit(1);
}
tfp = fopen(TUSERFILE, "r+");
if (tfp == NULL)
{
printf("can't open %s\n",TUSERFILE);
getch();
exit(1);
}
fscanf(fp, "%3d", &count);
fseek(fp, 0, 2);
fprintf(fp, FORMAT, p.user_name, p.password, p.email);
count++;
rewind(fp);
fprintf(fp, "%3d", count);
fclose(fp);
rewind(tfp);
fprintf(tfp, FORMAT, p.user_name, p.password, p.email);
fclose(tfp);
strcat(path,"account\\");
strcat(path,p.user_name);
strcat(path,"\\map.list");
strcat(dir,"account\\");
strcat(dir,p.user_name);
mkdir(dir);
fmap=fopen(path,"w");
fclose(fmap);
}
/**********************************************************************
功能说明:验证账户
参数说明:p 为要验证的账户
返回值说明:通过p中的message元素返回验证结果,若密码正确则1,找不到用户为2,密码错误为3,用户名重复为4
*********************************************************************/
void SearchAccount(Account * p)
{
FILE *fp,*tfp;
Account temp;
int n,i;
fp = fopen(USERFILE, "r+");
if (fp == NULL)
{
printf("can't open %s\n",USERFILE);
getch();
exit(1);
}
tfp = fopen(TUSERFILE, "r+");
if (tfp == NULL)
{
printf("can't open %s\n",TUSERFILE);
getch();
exit(1);
}
fscanf(fp,"%3d",&n);
for(i=0;i<n+1;i++)
{
fscanf(fp,FORMAT,temp.user_name,temp.password,temp.email);
if (strcmp(temp.user_name,p->user_name)==0)
strcpy(p->email,temp.email);
if(strcmp(temp.user_name,p->user_name)==0&&strcmp(temp.password,p->password)==0)
{
rewind(tfp);
fprintf(tfp, FORMAT,temp.user_name,temp.password,p->email );
fclose(tfp);
p->message=1;
return;
}
else if(strcmp(temp.user_name,p->user_name)==0&&strcmp(temp.password,p->password)!=0)
{
p->message=3;
return;
}
}
p->message=2;
fclose(fp);
}
/**********************************************************************
功能说明:寻找账户
参数说明:p 为要寻找的账户
返回值说明:未找到返回-1,找到返回用户注册的序号
*********************************************************************/
int SearchName(Account *p)
{
FILE *fp;
int n,i;
Account temp;
fp = fopen(USERFILE, "r+");
if (fp == NULL)
{
printf("can't open %s\n",USERFILE);
getch();
exit(1);
}
rewind(fp);
fscanf(fp,"%3d",&n);
for(i=0;i<n;i++)
{
fscanf(fp,FORMAT,temp.user_name,temp.password,temp.email);
if(strcmp(p->user_name,temp.user_name)==0)
{
p->message=4;
return i;
}
}
fclose(fp);
p->message=2;
return -1;
}
/**********************************************************************
功能说明:对Account中的message信息处理
参数说明:message 为信息标志,(x,y)为要显示结果的位置
返回值说明:无
*********************************************************************/
int ProcessMessage(int message,int x,int y)
{
switch (message)
{
case 1:
{
return 1;
}
case 2:
{
//PrintHZ16(x,y,"找不到用户",0xffff,1,1);
ErrorInfo(2);
ErrorCheck();
return 0;
}
case 3:
{
//PrintHZ16(x,y,"密码不正确",0xffff,1,1);
ErrorInfo(3);
ErrorCheck();
return 0;
}
case 4:
{
//PrintHZ16(x,y,"已经有同名用户",0xffff,1,1);
ErrorInfo(1);
ErrorCheck();
return 0;
}
}
return 1;
}
/**********************************************************************
功能说明:修改账号密码
参数说明:p为要修改的账户
返回值说明:无
*********************************************************************/
void ChangePassword(Account p)
{
int sta;
Account temp;
FILE *fp,*tfp;
sta=SearchName(&p);
if(sta==-1)
{
ProcessMessage(p.message,400,0);
return ;
}
fp = fopen(USERFILE, "r+");
if (fp == NULL)
{
printf("can't open %s\n",USERFILE);
getch();
exit(1);
}
tfp = fopen(TUSERFILE, "r+");
if (tfp == NULL)
{
printf("can't open %s\n",TUSERFILE);
getch();
exit(1);
}
fseek(fp,3+sta*60,0);
fscanf(fp,FORMAT,temp.user_name,temp.password,temp.email);
if(strcmp(p.email,temp.email)!=0)
{
PrintHZ16(400,0,"邮箱错误",0xffff,1,1);
return;
}
fseek(fp,3+sta*60,0);
fprintf(fp, FORMAT,p.user_name,p.password,p.email );
fclose(fp);
rewind(tfp);
fprintf(tfp,FORMAT,p.user_name,p.password,p.email);
fclose(tfp);
return;
}
/**********************************************************************
功能说明:读取当前账户信息
参数说明:p为地址传递的账户的地址
返回值说明:无
*********************************************************************/
void ReadCurrentAccount(Account *p)
{
FILE * tfp;
tfp = fopen(TUSERFILE, "r+");
if (tfp == NULL)
{
printf("can't open %s\n",TUSERFILE);
getch();
exit(1);
}
rewind(tfp);
fscanf(tfp,FORMAT,p->user_name,p->password,p->email);
return;
}
/**********************************************************************
功能说明:密码加密
参数说明:p为要加密的账户
返回值说明:无
*********************************************************************/
void Encrypt(Account *p)
{
char password[MAXLEN];
int i;
strcpy(password,p->password);
for(i=0;password[i]!='\0';i++)
{
password[i]=password[i]+3;
if(password[i]>'z'||password[i]>'Z'&&password[i]<'a')
{
password[i]-=26;
}
if(password[i]>'9'&&password[i]<'A')
{
password[i]-=10;
}
}
strcpy(p->password,password);
}