-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth system
More file actions
168 lines (141 loc) · 4.73 KB
/
Copy pathauth system
File metadata and controls
168 lines (141 loc) · 4.73 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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#define _CRT_SECURE_NO_WARNINGS
#define D_CRT_NONSTDC_NO_WARNINGS
void logger(FILE*, int, char*);
char* dynstring(char);
int main() {
FILE *fth = fopen("C:\\Users\\Timur\\Desktop\\logins.txt", "r");
if (fth == NULL) {
//error
return 0;
}
char rights = 0;
printf("-----------Authorizathion-----------\n");
printf("Enter your login: ");
char *login = dynstring('\n');
printf("\nEnter your password: ");
char *password = dynstring('\n');
char temp = '0';
while (temp != EOF) {
int i = 0;
for (; (temp = fgetc(fth)) != ';' && login[i] != '\0' && login[i] == temp; ++i);
if (login[i] == '\0' && temp == ';') {
i = 0;
for (; (temp = fgetc(fth)) != ';' && password[i] != '\0' && password[i] == temp; ++i);
if (password[i] == '\0' && temp == ';') {
rights = (fgetc(fth) - '0') << 1;
fgetc(fth);
rights += fgetc(fth) - '0';
//printf("\nrights: %d ", rights);
break;
} else {
//error_code(4)
}
} else {
while ((temp = fgetc(fth)) != '\n' && temp != EOF);
}
}
if (!rights) {
return 22;
} else {printf("\nGOD");}
// rights in template
fclose(fth);
return 0;
}
/*
int word_length (char ch) {
int length = 0;
char buf;
for(; (buf!=getchar()) != ch; ++length);
return length;
} // ch - our separator symbol
char* dynstring (char ch) {
int length = word_length(ch);
char* word = (char*)malloc((length+1) * sizeof(char));
for(int i=0;i<length+1;++i){
freopen();
}
}
*/
char* dynstring(char c) {
int l = 0;
int size = 1;
char *string = (char*) malloc(size * sizeof(char));
char ch = getchar();
while (ch != c) {
string[(l)++] = ch;
if (l >= size) {
size *= 2;
string = (char*) realloc(string, size * sizeof(char));
}
ch = getchar();
}
string[l] = '\0';
return string;
}
char* timeinf();
void logger_book(FILE* fth, int code, char* login){
char* time = timeinf();
fprintf(fth, "{\t\"time\" = %s\";\t\"login\" = \"%s\";\t\"operation\" = \"", time,login);
switch (code) {
case 0: fputs("Entered in the library\"}",fth); break; //Auth accepted
case 1: fputs("Add book to the library \"}",fth); break;
case 2: fputs("Delete's book from the library\"}",fth); break;
case 3: fputs("Edit's book in library\"}",fth); break;
case 4: fputs("Lists books\"}",fth); break;
case 5: fputs("Search books by author surname\"}",fth); break;
case 6: fputs("Change count of books by ISBN\"}",fth); break;
case 7: fputs("Backups the library\"}",fth); break;
case 8: fputs("Open library backup\"}",fth); break;
case 9: fputs("Exit from library\"}",fth); break;
case 10: fputs("Get book from library\"}",fth); break;
case 11: fputs("Bring book in library\"}",fth); break;
default:break;
}
fprintf(fth, "\"\n");
free(time);
}
void logger_student(FILE* fth, int code, char* login){
char* time = timeinf();
fprintf(fth, "{\t\"time\" = %s\";\t\"login\" = \"%s\";\t\"operation\" = \"", time,login);
switch (code) {
case 0: fputs("Entered in the student database\"}",fth); break; //Auth accepted
case 1: fputs("Add student in database \"}",fth); break;
case 2: fputs("Delete's student from database\"}",fth); break;
case 3: fputs("Edit's information about student in database\"}",fth); break;
case 4: fputs("Lists student by number of student book\"}",fth); break;
case 5: fputs("Search students by surname\"}",fth); break;
case 6: fputs("Backups the library\"}",fth); break;
case 7: fputs("Open library backup\"}",fth); break;
case 8: fputs("Exit from student database\"}",fth); break;
default:break;
}
fprintf(fth, "\"\n");
free(time);
}
//fputs("\entered in the library"\n}",fth); break;
// CH_CODES
// Enter into the library !!! *done*
// Add's book to the library
// Delete's book from the library
// Edit's book in library
// Lists books
// Search books by author surname
// Change count of books by ISBN
// Backups the library
// Open library backup
// Exit from library
// Get book from library
// Bring book in library
char* timeinf(){
const time_t timer = time(NULL) + 3600*3;
char* tm =(char*)malloc(20*sizeof(char));
struct tm* timeinf = localtime(&timer);
strftime (tm,20,"%d.%m.%Y %X.",timeinf);
//printf("%s\n",buffer);
return tm;
}
//fprintf(fth, "%s\n", tm);