Advertisement
Guest User

Untitled

a guest
Nov 6th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <stdlib.h>
  5.  
  6. using namespace std;
  7.  
  8. class user{
  9.     string username;
  10.     string password;
  11.     string userCheck;
  12.     string passCheck;
  13.  
  14. public:
  15.  
  16.     user(string u, string p){
  17.         username=u;
  18.         password=p;
  19.     }
  20.  
  21.     //fungsi untuk mengecek ketersediaan username
  22.     int checkUser(){
  23.         int c=0;
  24.         ifstream myfile ("dataUser.txt");
  25.         while(myfile){
  26.             getline(myfile,userCheck,';');
  27.             getline(myfile,passCheck);
  28.             if (userCheck==username)
  29.                 c=1;
  30.             else c=0;
  31.             if (c==1)
  32.                 break;
  33.         }
  34.         myfile.close();
  35.         if(c==1)
  36.             return 1;
  37.         else return 0;
  38.     }
  39.  
  40.     void userRegis(){
  41.             ofstream myfile("dataUser.txt",ios::app);
  42.             myfile<<username<<";";
  43.             myfile<<password<<endl;
  44.             myfile.close();
  45.             system("cls");
  46.             cout<<"\tREGISTRASI"<<endl;
  47.             cout<<"------------------------------"<<endl;
  48.             cout<<"REGISTRASI SUKSES"<<endl;
  49.             system("pause");
  50.         }
  51.  
  52.     int loginCheck(){
  53.         ifstream myfile ("dataUser.txt");
  54.         int c=0;
  55.         while (myfile){
  56.             getline(myfile,userCheck,';');
  57.             getline(myfile,passCheck);
  58.             if((userCheck==username) && (passCheck==password))
  59.                 c=1;
  60.             else c=0;
  61.             if (c==1)
  62.                 break;
  63.         }
  64.         cout<<c<<endl;
  65.         if (c==1)
  66.             return 0;
  67.         else return 1;
  68.     }
  69.  
  70.     void userLogin(){
  71.         system("cls");
  72.         cout<<"sukses";
  73.     }
  74. };
  75.  
  76. void menu(){
  77.     cout<<"ini menu"<<endl;
  78.     system("pause");
  79. }
  80.  
  81. int main()
  82. {
  83.     int pil;
  84.     string username,password;
  85.     user userObj(username,password);
  86.  
  87.     cout<<"1. Masuk"<<endl;
  88.     cout<<"2. Registrasi"<<endl;
  89.     cout<<"3. Keluar"<<endl;
  90.     cout<<"-----------------------"<<endl;
  91.     cout<<"Masukkan Pilihan Anda: "; cin>>pil;
  92.  
  93.     if(pil==1){
  94.         system("cls");
  95.         cout<<"\tLOGIN"<<endl;
  96.         cout<<"------------------------------"<<endl;
  97.         cout<<"Masukkan Username Anda: "; cin>>username;
  98.         cout<<"Masukkan Password Anda: "; cin>>password;
  99.         user userObj(username,password);
  100.  
  101.         if(userObj.loginCheck()==1){
  102.             system("cls");
  103.             cout<<"\tLOGIN"<<endl;
  104.             cout<<"------------------------------"<<endl;
  105.             cout<<"USERNAME ATAU PASSWORD SALAH"<<endl;
  106.             system("pause");
  107.             system("cls");
  108.             main();
  109.         }else {
  110.             userObj.userLogin();
  111.             menu();
  112.         }
  113.     }else if (pil==2){
  114.         system("cls");
  115.         cout<<"\tREGISTRASI"<<endl;
  116.         cout<<"------------------------------"<<endl;
  117.         cout<<"Masukkan Username Anda: "; cin>>username;
  118.         cout<<"Masukkan Password Anda: "; cin>>password;
  119.         user userObj(username,password);
  120.         if(userObj.checkUser()==1){
  121.             system("cls");
  122.             cout<<"\tREGISTRASI"<<endl;
  123.             cout<<"------------------------------"<<endl;
  124.             cout<<"USERNAME TIDAK TERSEDIA"<<endl;
  125.             system("pause");
  126.             system("cls");
  127.             main();
  128.         }else {
  129.             userObj.userRegis();
  130.             system("cls");
  131.             main();
  132.         }
  133.     }else if(pil==3)
  134.         return 0;
  135.     return 0;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement