-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_client.cpp
More file actions
executable file
·87 lines (81 loc) · 2.24 KB
/
function_client.cpp
File metadata and controls
executable file
·87 lines (81 loc) · 2.24 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
/*
TO DO function:
User:
signup();
login();
logChat();
viewChatFile();
Server:
signup();
login();
listUser();
viewChatFile();
substrUser();
substrPasswd();
*/
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
class Server{
public:
char data[100];
ofstream ofile;
ifstream ifile;
void signup(){
ofile.open("userlist.txt");
ofile << "adwisatya adwisatyapwd";
cout << "Pendaftaran berhasil";
}
int login(string username,string password){
cout << password << getPassword(username);
return password==getPassword(username);
}
string substrUser(string input){
int delimitedPosition;
delimitedPosition = input.find(" ");
return input.substr(0,delimitedPosition);
}
string substrPasswd(string input){
int delimitedPosition;
delimitedPosition = input.find(" ");
return input.substr(delimitedPosition+1,input.length());
}
string getPassword(string username){
string line;
string password = "";
int delimitedPosition;
ifile.open("userlist.txt");
if(ifile.is_open()){
while(getline(ifile,line)){
if(substrUser(line)==username){
password = substrPasswd(line);
false;
}
}
ifile.close();
}
return password;
}
void listUser(){
string line;
ifile.open("userlist.txt");
if(ifile.is_open()){
while(getline(ifile,line)){
cout << substrUser(line) << endl;
}
ifile.close();
}
}
};
int main(){
Server server;
//server.signup();
server.listUser();
//cout << endl << "Password dari adwis2atya" << server.getPassword("adwis2atya")<<endl;
//string manip = "aryya oke";
//int delimiterPosotion = manip.find(" ");
//cout << manip.substr(0, manip.find(" "));
cout << server.login("asdasdasd","asdasdas") << endl;
return 0;
}