Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5. //Base Definitions
  6. #define Welcome_Message "Welcome to simple-login 1887\nDeveloped by Average Industries"
  7. #define Max_Accounts 20
  8. //Global Variables
  9. int i=0;
  10. int TotalAccounts;
  11. //Function Declarations
  12. void StartProgram();
  13. int GetLength(string);
  14. string GetArgument(string,int);
  15. bool IsNumerical(string);
  16. void RegisterScreen();
  17. void LoginScreen();
  18. int CountAccounts();
  19. void CreateFiles();
  20. string ReadFromFile(string);
  21. //On script startup
  22. int main()
  23. {
  24.     CreateFiles();
  25.     TotalAccounts = CountAccounts();
  26.     cout << "DEBUG: " << TotalAccounts << " active accounts" << endl;
  27.     StartProgram();
  28.     system("pause");
  29.     return 0;
  30. }
  31. //Functions
  32. void StartProgram()
  33. {
  34.     cout << Welcome_Message << endl;
  35.     string response;
  36.     cout << "Please enter 'register' or 'login'" << endl;
  37.     while(2==2)
  38.     {
  39.         getline(cin,response);
  40.         if(response == "register") { RegisterScreen(); break; }
  41.         else if(response == "login") { break; }
  42.     }
  43. }
  44.  
  45. string GetArgument(string word,int argument)//finds a phrase in a string seperated by spaces
  46. {
  47.     cout << "DEBUG: Distinguishing argument" << endl;
  48.     string word1;
  49.     string answer;
  50.     int length,originallength = GetLength(word);
  51.     int start,argumentstotal = 1;
  52.    
  53.     if(argument == 1) length = 0;
  54.     else length = -1;
  55.     for (i=0;i<=10000;i++)
  56.     {
  57.         length ++;
  58.         word1 = word[i];
  59.         if(word1 == " ") argumentstotal ++;
  60.         if(argumentstotal == argument || length >= originallength)
  61.         {
  62.             if(i != 0)start = i+1;
  63.             else start = 0;
  64.             break;
  65.         }
  66.     }
  67.     for(i=start;i<=10000;i++)
  68.     {
  69.         length ++;
  70.         word1 = word[i];
  71.         if(word1 == " " || originallength <= length) break;
  72.         answer = answer + word1;
  73.     }
  74.     cout << "DEBUG: Arument found, returning: " << answer << endl;
  75.     return answer;
  76. }
  77.  
  78. bool IsNumerical(string word)
  79. {
  80.     string word1;
  81.     bool numerical = true;
  82.     int b;
  83.     int wordlength = GetLength(word) -1;
  84.     for(i=0;i<=wordlength;i++)
  85.     {
  86.         word1 = word[i];
  87.         if(word1 != "1" && word1 != "2" && word1 != "3" && word1 != "4" && word1 != "5" && word1 != "6" && word1 != "7" && word1 != "8" && word1 != "9" && word1 != "0")
  88.         {
  89.             numerical = false;
  90.             break;
  91.         }
  92.     }
  93.     return numerical;
  94. }
  95.  
  96. int CountAccounts()
  97. {
  98.     string answer;
  99.     string line;
  100.     ifstream infile;
  101.     infile.open ("ProgramData/SimpleLogin/Accounts.txt");
  102.     getline(infile,line);
  103.     infile.close();
  104.     int b;
  105.     for(b=1;b<=Max_Accounts +1;b++)
  106.     {
  107.         answer = GetArgument(line,b);
  108.         if(answer != "Null") cout << "DEBUG: Argument " << b << " does not contain 'Null'" << endl;
  109.         else { cout << "DEBUG: Argument " << b << " contains 'Null'\nDEBUG: Breaking loop\n"; break; }
  110.     }
  111.     return b - 1;
  112. }
  113.  
  114. int GetLength(string word)//Do not use on empty strings
  115. {
  116.     cout << "DEBUG: Fetching word length" << endl;
  117.     string answer;
  118.     int length;
  119.    
  120.     for (i=0;i<=10000;i++)
  121.     {
  122.         answer = answer + word[i];
  123.         if(answer == word) { length = i+1; break; }
  124.     }
  125.     cout << "DEBUG: Length found, returning " << length << endl;
  126.     return length;
  127. }
  128.  
  129. void CreateFiles()
  130. {
  131.     ofstream outputfile0("ProgramData/SimpleLogin/Accounts.txt",ios::app);
  132.     bool run;
  133.     string runbefore;
  134.     ifstream infile;
  135.     infile.open ("ProgramData/SimpleLogin/Run.txt");
  136.     getline(infile,runbefore);
  137.     infile.close();
  138.     cout << "DEBUG: Checking file: Run.txt" << endl << "DEBUG: File: " << runbefore << endl;
  139.     if(runbefore != "Yes") run = false;
  140.     else run = true;
  141.     if(run == false)
  142.     {
  143.         outputfile0 << "Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null";
  144.         ofstream outputfile2("ProgramData/SimpleLogin/Run.txt");
  145.         cout << "Creating Needed files" << endl;
  146.         outputfile2 << "Yes";
  147.     }  
  148. }
  149.  
  150. void RegisterScreen()
  151. {
  152.     cout << "\n**************************\nAccount Registration\n**************************\n";
  153.     string UserName,Password;
  154.     cout << "Desired Username: ";
  155.     while(2==2)
  156.     {
  157.         getline(cin,UserName);
  158.         if(GetLength(UserName) < 10) cout << "Username must be at least 10 characters long" << endl;
  159.         else break;
  160.     }
  161.     while(2==2)
  162.     {
  163.         string answer,word;
  164.         int b;
  165.         ////////////////////
  166.         string line,line2;
  167.         ifstream infile;
  168.         infile.open ("ProgramData/SimpleLogin/Accounts.txt");
  169.         getline(infile,line);
  170.         infile.close();
  171.         /////////////////
  172.         for(b=0;b<=(Max_Accounts*2)-1;b++)
  173.         {
  174.             word = GetArgument(line,b);
  175.             if(b != TotalAccounts) line2 = (line2 + word) + " ";
  176.             else line2 = (line2 + UserName) + " ";
  177.         }
  178.         cout << "Desired Password: ";
  179.         getline(cin,Password);
  180.         for(b=0;b<=Max_Accounts*2;b++)
  181.         {
  182.             word = GetArgument(line2,b);
  183.             if(b != (TotalAccounts*2)+2) answer = (answer + word) + " ";
  184.             else answer = (answer + Password) + " ";
  185.         }
  186.         if(GetLength(Password) < 8) cout << "Password must be at least 8 characters long" << endl;
  187.         else
  188.         {
  189.             ofstream outputfile1("ProgramData/SimpleLogin/Accounts.txt");
  190.             outputfile1 << answer;
  191.             break;
  192.         }
  193.     }
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement