Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <stdlib.h>
- using namespace std;
- class user{
- string username;
- string password;
- string userCheck;
- string passCheck;
- public:
- user(string u, string p){
- username=u;
- password=p;
- }
- //fungsi untuk mengecek ketersediaan username
- int checkUser(){
- int c=0;
- ifstream myfile ("dataUser.txt");
- while(myfile){
- getline(myfile,userCheck,';');
- getline(myfile,passCheck);
- if (userCheck==username)
- c=1;
- else c=0;
- if (c==1)
- break;
- }
- myfile.close();
- if(c==1)
- return 1;
- else return 0;
- }
- void userRegis(){
- ofstream myfile("dataUser.txt",ios::app);
- myfile<<username<<";";
- myfile<<password<<endl;
- myfile.close();
- system("cls");
- cout<<"\tREGISTRASI"<<endl;
- cout<<"------------------------------"<<endl;
- cout<<"REGISTRASI SUKSES"<<endl;
- system("pause");
- }
- int loginCheck(){
- ifstream myfile ("dataUser.txt");
- int c=0;
- while (myfile){
- getline(myfile,userCheck,';');
- getline(myfile,passCheck);
- if((userCheck==username) && (passCheck==password))
- c=1;
- else c=0;
- if (c==1)
- break;
- }
- cout<<c<<endl;
- if (c==1)
- return 0;
- else return 1;
- }
- void userLogin(){
- system("cls");
- cout<<"sukses";
- }
- };
- void menu(){
- cout<<"ini menu"<<endl;
- system("pause");
- }
- int main()
- {
- int pil;
- string username,password;
- user userObj(username,password);
- cout<<"1. Masuk"<<endl;
- cout<<"2. Registrasi"<<endl;
- cout<<"3. Keluar"<<endl;
- cout<<"-----------------------"<<endl;
- cout<<"Masukkan Pilihan Anda: "; cin>>pil;
- if(pil==1){
- system("cls");
- cout<<"\tLOGIN"<<endl;
- cout<<"------------------------------"<<endl;
- cout<<"Masukkan Username Anda: "; cin>>username;
- cout<<"Masukkan Password Anda: "; cin>>password;
- user userObj(username,password);
- if(userObj.loginCheck()==1){
- system("cls");
- cout<<"\tLOGIN"<<endl;
- cout<<"------------------------------"<<endl;
- cout<<"USERNAME ATAU PASSWORD SALAH"<<endl;
- system("pause");
- system("cls");
- main();
- }else {
- userObj.userLogin();
- menu();
- }
- }else if (pil==2){
- system("cls");
- cout<<"\tREGISTRASI"<<endl;
- cout<<"------------------------------"<<endl;
- cout<<"Masukkan Username Anda: "; cin>>username;
- cout<<"Masukkan Password Anda: "; cin>>password;
- user userObj(username,password);
- if(userObj.checkUser()==1){
- system("cls");
- cout<<"\tREGISTRASI"<<endl;
- cout<<"------------------------------"<<endl;
- cout<<"USERNAME TIDAK TERSEDIA"<<endl;
- system("pause");
- system("cls");
- main();
- }else {
- userObj.userRegis();
- system("cls");
- main();
- }
- }else if(pil==3)
- return 0;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement