Advertisement
Guest User

Untitled

a guest
Jun 18th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <locale>
  5.  
  6. #define VERSION "1.0"
  7. #define AUTHOR "Melvin Koopmans"
  8.  
  9. using namespace std;
  10.  
  11. string username;
  12. string password;
  13. string line;
  14. int option;
  15. char back;
  16. char loginyn;
  17.  
  18. template < typename Iter >
  19. void range_tolower ( Iter beg, Iter end ) {
  20. for( Iter iter = beg; iter != end; ++iter ) {
  21. *iter = tolower( *iter );
  22. }
  23. }
  24.  
  25. void string_tolower ( std::string & str ) {
  26. range_tolower( str.begin(), str.end() );
  27. }
  28.  
  29. int loginform()
  30. {
  31.     cout << "Login" << endl;
  32.     cout << "Username: ";
  33.     cin >> username;
  34.     cout << "Password: ";
  35.     cin >> password;
  36.     string_tolower( username );
  37.     ifstream datafile (username+".txt");
  38.     if (datafile.is_open())
  39.     {
  40.     while (! datafile.eof() )
  41.     {
  42.       getline (datafile,line);
  43.       if ( line == password )
  44.       {
  45.           cout << "Welcome " << username << "!" << endl;
  46.       }
  47.     }
  48.     datafile.close();
  49.     }
  50.     else
  51.     {
  52.           cout << "Invalid login!" << endl;
  53.     }
  54.     return 0;
  55. }
  56.  
  57. int registerform()
  58. {
  59.     cout << "Register" << endl;
  60.     backregister:
  61.     cout << "Username: ";
  62.     cin >> username;
  63.     cout << "Password: ";
  64.     cin >> password;
  65.     string_tolower( username );
  66.     ofstream datafile;
  67.     datafile.open (username+".txt");
  68.     datafile << password;
  69.     datafile.close();
  70.     cout << "Registed Succesfuly!" << endl;
  71.     loginynback:
  72.     cout << "Login now[y/n]?: ";
  73.     cin >> loginyn;
  74.  
  75.     if ( loginyn == 'y' )
  76.     {
  77.         loginform();
  78.     }
  79.     else if ( loginyn == 'n')
  80.     {
  81.     }
  82.  
  83.     else
  84.     {
  85.         cout << "Invalid option!" << endl;
  86.         goto loginynback;
  87.     }
  88.  
  89.     return 0;
  90. }
  91.  
  92. int main()
  93. {
  94.     start:
  95.     cout << "MyProgram " << VERSION << endl;
  96.     cout << "1. Login" << endl;
  97.     cout << "2. Register" << endl;
  98.     cout << "3. Credits" << endl;
  99.     cout << "4. Exit" << endl;
  100.     cout << "Choose an option: ";
  101.     cin >> option;
  102.    
  103.     if ( option == 1 )
  104.     {
  105.         loginform();
  106.     }
  107.     else if ( option == 2 )
  108.     {
  109.         registerform();
  110.     }
  111.     else if ( option == 3 )
  112.     {
  113.         cout << "Made by: Melvin Koopmans" << endl;
  114.         cout << "Made in C++ " << endl;
  115.         cout << " " << endl;
  116.         back2:
  117.         cout << "Back[y/n]?: ";
  118.         cin >> back;
  119.  
  120.         if ( back == 'y' )
  121.         {
  122.             cout << " " << endl;
  123.             goto start;
  124.         }
  125.         else if ( back == 'n' )
  126.         {
  127.            
  128.         }
  129.         else
  130.         {
  131.             cout << "Invalid option!" << endl;
  132.             goto back2;
  133.         }
  134.     }
  135.  
  136.     else if ( option == 4 )
  137.     {
  138.        
  139.     }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement