-
Notifications
You must be signed in to change notification settings - Fork 0
/
LOGIN.CPP
95 lines (94 loc) · 1.62 KB
/
LOGIN.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
#include"HEADERS\HEADER.h"
char *user::retpass()
{
return pass;
}
char *user::retname()
{
return name;
}
void user::getpass()
{
cout<<"\nEnter your password\n(MAX 6 length)";
gets(pass);
}
void user::writetofile()
{
ofstream fout("database",ios::binary|ios::app);
fout.write((char *)&this,sizeof(user));
fout.close();
}
void user::getdata()
{
cout<<"Enter your name\n";
gets(name);
if(!(strcmpi(name,"NALIN"))||!(strcmpi(name,"HARSHIT")))
isadmin=1;
getpass();
writetofile();
}
void loading()
{
clrscr();
textcolor(BLUE);
cout<<"\t\t\t";
for(int i=0;i<=20;i++)
{
delay(200);
cprintf("%c",178);
gotoxy(34,2);
cprintf("%i",i*5);
cprintf("%");
gotoxy(24+i,1);
}
}
void login()
{
user temp;
char passtemp[6],nametemp[100],ch;
cout<<"Enter username\n"; cin.getline(nametemp,100);
cout<<"Enter password(leave empty if a new user)(MAX length 6)\n";
int i=0,check=0;
while(i<6)
{
ch=getch();
cout<<'*';
if(ch=='\n')
break;
passtemp[i++]=ch;
}
tm * logintime;
time_t abc=time(0);
logintime = localtime(&abc);
passtemp[i]='\0';
loading();
clrscr();
cout.write(passtemp,6);
ifstream fin("database",ios::binary);
while(fin.read((char *)&temp,sizeof(temp)))
{
if(fin.eof()) break;
cout<<"hello";
if(!(strcmpi(passtemp,temp.retpass()))&&!(strcmpi(nametemp,temp.retname())))
{
check=1;
break;
}
}
fin.close();
if(!check)
{
cout<<"New user detected\n";
temp.getdata();
logi.log_newuser(temp, logintime);
}
else
{
cprintf("Welcome");
cprintf(temp.retname());
logi.log_olduser(temp, logintime);
}
if(temp.admin())
cout<<"ADMIN DETECTED\n";
logi.log_admin(temp, logintime);
}