-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsistem.h
53 lines (40 loc) · 1.23 KB
/
sistem.h
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
#include<stdio.h>
#include<string.h>
int sistem_login(int banyakArgumen, char *argumen[]) {
/*
FILE *fbw = fopen("database/login.bin", "wb");
char login[20] = "Kelompok@Satu";
fwrite(login, sizeof(char), sizeof(login)/sizeof(char), fbw);
*/
if (banyakArgumen != 3) {
printf("Gagal Login! Argumen tidak sesuai. Ikuti format berikut.\n");
printf("./FileAplikasiProgramUtama username password\n");
return 1;
}
char usernameInput[10], passwordInput[10];
strcpy(usernameInput, argumen[1]);
strcpy(passwordInput, argumen[2]);
FILE *fbw;
if ((fbw = fopen("database/login.bin", "rb")) == NULL) {
printf("Gagal membuka file!\n");
return 1;
}
char akun[20];
fread(akun, sizeof(char), sizeof(akun)/sizeof(char), fbw);
fclose(fbw);
char *string[3];
char username[20], password[20];
int ctrl = 0;
string[0] = strtok(akun, "@");
while(string[ctrl++] != NULL) {
string[ctrl] = strtok(NULL, "@");
}
strcpy(username, string[0]);
strcpy(password, string[1]);
if ((strcmp(usernameInput, username) == 0) && (strcmp(passwordInput, password) == 0)) {
return 0;
} else {
return 1;
}
return 0;
}