-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthentication.cpp
More file actions
80 lines (75 loc) · 1.84 KB
/
Copy pathauthentication.cpp
File metadata and controls
80 lines (75 loc) · 1.84 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
#include<iostream>
#include<fstream>
#include<string.h>
#include<string>
using namespace std;
class Login_Register{
string Email,password;
public:
bool checkString(string passed,string inFile)
{
int size1=passed.length();
int size2=inFile.length();
if(size1==size2)
{
for(int i=0;i<size1;i++)
{
if(passed[i]!=inFile[i])
{
return false;
}
}
return true;
}
else
return false;
}
void Register()
{
ofstream fout("userdata.txt",ios::app);
cin.ignore();
cout<<"Enter Email : ";getline(cin,Email);
cout<<"Enter password: ";getline(cin,password);
fout<<Email<<" "<<password<<" ";
fout.close();
}
void login(string mail,string pass)
{
ifstream fout("userdata.txt",ios::in);
while(!fout.eof())
{
fout>>Email>>password;
if(checkString(mail,Email) && checkString(pass,password))
{
cout<<"Welcome";
break;
}
}
fout.close();
}
};
int main()
{
Login_Register obj1;
string email, pass;
int opt=1; //for 1st time
cout<<"Press 1 to Login"<<endl;
cout<<"Press 2 to Register" <<endl;
cout<<"Press 3 to Exit"<<endl;
while(opt==1||opt==2)
{
cout<<"\nEnter choice: ";
cin>>opt;
if(opt==1)
{ cin.ignore();
cout<<" Email : "; getline(cin,email);
cout<<" Password : "; getline(cin,pass);
obj1.login(email,pass);
}
else if(opt==2)
{
obj1.Register();
}
}
system("pause>0");
}