-
Notifications
You must be signed in to change notification settings - Fork 1
/
auth.cpp
139 lines (110 loc) · 2.82 KB
/
auth.cpp
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
/*
File Name : auth.cpp
Description :
Author : Garly Nugraha & Nazwa Fitriyani Zahra
Date : 30/12/2001
*/
/* ========== Header File ========== */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
#include "auth.h"
#include "user.h"
#include "compare.h"
#include "administrator.h"
#include "concierge.h"
#include "session.h"
#include "welcome.h"
#include "hidden.h"
/* ======= End of Header File ====== */
int Login()
{
User UserData, TempUserData;
FILE *f_user, *f_tempuser;
int CompareUsername, ComparePassword;
printf("|==================================|\n");
printf("| Login |\n");
printf("|==================================|\n");
printf("\n\n");
printf("Username : ");
fflush(stdin);
scanf("%[^\n]", &TempUserData.Username);
printf("Password : ");
fflush(stdin);
HiddenPassword(TempUserData.Password);
printf("\n");
fflush(stdin);
/* Open File */
f_user = fopen("User.DAT", "rb");
f_tempuser = fopen("TempUser.DAT", "wb");
/* Error Handle About Open File */
if (!f_user)
{
printf ("ERROR : Sorry the file is unavailable!!!\n");
printf("Press Any Key to continue . . .");
getch();
system("cls");
Welcome();
}
/* Error Handle About Open File */
if (!f_tempuser)
{
printf ("ERROR : Sorry the file is unavailable!!!\n");
printf("Press Any Key to continue . . .");
getch();
system("cls");
Welcome();
}
while (fread(&UserData, sizeof(UserData), 1, f_user))
{
CompareUsername = StringCompare(UserData.Username, TempUserData.Username);
ComparePassword = StringCompare(UserData.Password, TempUserData.Password);
if((CompareUsername == 0) && (ComparePassword == 0)){
TempUserData.Code = UserData.Code;
strcpy(TempUserData.FullName, UserData.FullName);
strcpy(TempUserData.Email, UserData.Email);
TempUserData.Role = UserData.Role;
TempUserData.Status = 1;
fwrite(&TempUserData, sizeof(TempUserData), 1, f_tempuser);
}
else {
fwrite(&UserData, sizeof(UserData), 1, f_tempuser);
}
}
/* Close File */
fclose(f_user);
fclose(f_tempuser);
/* Remove File */
remove("User.DAT");
/* Rename File */
rename("TempUser.DAT", "User.DAT");
if (TempUserData.Role == 1){
system("cls");
/* Call Modul Menu Administrator */
AdministratorMenu();
} else if(TempUserData.Role == 2){
system("cls");
/* Call Modul Menu Concierge */
ConciergeMenu();
} else{
system("cls");
printf ("ERROR : Username or Password is incorrect!!!\n");
printf("Press Any Key to continue . . .");
getch();
system("cls");
/* Call Modul Welcome */
Welcome();
}
}
int Logout()
{
/* Call Modul Session Destroy */
SessionDestroy();
printf ("Account successfully logout!!!\n");
getch();
system("cls");
/* Call Modul Welcome */
Welcome();
}