Advertisement
okelikai

campusShopLogin

Oct 20th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip> //setw
  3. #include <cmath> // math
  4. #include <fstream>
  5. #include <cstring>
  6. #include <string>
  7. #include <map>
  8. #include <algorithm>
  9.  
  10. using namespace std;
  11.  
  12. // Big Daddy Menu ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  13.  
  14. // hey future coder, when menu is written it needs parameters
  15. // username,
  16.  
  17. void menu(string username, string password) {
  18.     cout << "Hi";
  19. }
  20. // USERS ********************************************************
  21. void addNewMembers(string name, string encrypt) {  // parameters are put to figure use variables in other functions of code
  22.     string save;
  23.     ofstream Users; // file stream
  24.     Users.open("txt/Users.txt", ios::app);
  25.     if(Users.is_open()) {
  26.         Users << name << ':' << encrypt << '\n';  // appends to file called Users
  27.     } else {
  28.         cout << "Error with file opening";
  29.     }
  30.     Users.close();
  31.     save = name + "." + encrypt;
  32.    
  33.     menu(name, save);
  34.    
  35. }
  36.  
  37. void algorithmNewUser(string ps, string name_of_user) {
  38.     string hashnsalt; // acts sorta like a transitional function
  39.    
  40.     reverse(ps.begin(),ps.end());
  41.     hashnsalt = ps + "6" ;
  42.     reverse(hashnsalt.begin(),hashnsalt.end());
  43.     hashnsalt += "8";
  44.     reverse(hashnsalt.begin(),hashnsalt.end());
  45.  
  46.     // cout << hashnsalt << "\n";   #++++++++++++++++++ FLAG ALERT
  47.     addNewMembers(name_of_user, hashnsalt);
  48. }
  49.  
  50. void newUser() {
  51.     string username, password;
  52.     cout << "Input a new username: ";
  53.     cin >> username;
  54.     while((4) != password.length()) {  // if length != 4 then keep running
  55.         cout << "Input a 4 number pin as a password: ";
  56.         cin >> password;
  57.     }
  58.     algorithmNewUser(password, username);
  59. }
  60. //////////////////////////////////////// THE GREAT WALL OF USERS
  61.  
  62.  
  63. void welcomingReturningMember(string ps, string userName) { // welcomes returning user and also checks for username via password
  64.     string username, key, line, save;
  65.     int elseChoice;
  66.     int j = 1; // it's the runner again
  67.  
  68.     fstream Users;
  69.    
  70.     key = userName + ":" + ps;
  71.     Users.open("txt/Users.txt");
  72.     if(Users.is_open()) {
  73.        
  74.        
  75.        
  76.        
  77.         while (!Users.eof() && (j == 1)) {
  78.             getline(Users,line);
  79.             if(key == line) {
  80.                 cout << "Welcome back, " << userName << "!";
  81.                 break;
  82.             }
  83.             else {
  84.                 cout << "User not found\n";
  85.                 cout << "New Account?\n[Enter integer]\n1.Yes\n2.No\n>";
  86.                 cin >> elseChoice;
  87.                 switch(elseChoice) {
  88.                     case 1:
  89.                         j -= 1;
  90.                         newUser();
  91.                         break;
  92.                     case 2:
  93.                         j -= 1;
  94.                         cout << "Too bad, you are becoming a New Member\n\n";
  95.                         newUser();
  96.                         break;
  97.                     default:
  98.                         cout << "Okay well, that's not a choice";
  99.                     }
  100.  
  101.             }
  102.         }
  103.        
  104.        
  105.        
  106.        
  107.        
  108.        
  109.        
  110.        
  111.     } else {
  112.         cout << "File not working";
  113.     }
  114.     save = userName + "." + ps;
  115.     menu(userName, save);
  116. }
  117.  
  118. void returningUserAlgorithm(string pswd, string user) {
  119.     string saltyhash; // just a standard decaration fam
  120.     reverse(pswd.begin(),pswd.end());   // reverses the order
  121.     saltyhash = pswd + "6";
  122.     reverse(saltyhash.begin(),saltyhash.end());
  123.     saltyhash += "8";
  124.     reverse(saltyhash.begin(),saltyhash.end());// finishes the 6br8-Algoritm
  125.  
  126.     welcomingReturningMember(saltyhash, user);
  127. }
  128.  
  129. void returningUser() {
  130.     string username, password;
  131.     cout << "Enter username: ";
  132.     cin >> username;
  133.    
  134.     while((4) != password.length()) {
  135.         cout << "Enter password: ";
  136.         cin >> password;
  137.     }
  138.     returningUserAlgorithm(password, username);
  139. }
  140.  
  141. void user() {
  142.     int user_choice, runner = 1;
  143.     string user_prompt;
  144.    
  145.     while(runner == 1) {
  146.         user_prompt = "[Enter digit]\n1.New User\n2.Returning User\n>";
  147.    
  148.         cout << user_prompt;
  149.         cin >> user_choice;
  150.         switch(user_choice) {
  151.             case 1:
  152.                 runner -= 1;
  153.                 newUser();
  154.                 break;
  155.             case 2:
  156.                 runner -= 1;
  157.                 returningUser();
  158.                 break;
  159.             default:
  160.                 cout << "Not a valid choice";
  161.                 break;
  162.         }    
  163.     }
  164.    
  165.    
  166. }
  167.  
  168. //
  169. void buyingMenu() {
  170.     int runner = 1;
  171.     char userChoice;
  172.     while (runner == 1) {
  173.         cout << "Inventory: ";
  174.             cout << "1: Father Azzarto Bobblehead: 25 Tokens.\n";
  175.             cout << "2: Gloves: 7 Tokens.\n";
  176.             cout << "3: Large Duffle Bag: 30 Tokens.\n";
  177.             cout << "4: Winter Had: 20 Tokens.\n";
  178.             cout << "5: Black Quilted Jacket: 45 Tokens.\n";
  179.             cout << "6: Varsity Sweater: 50 Tokens.\n";
  180.             cout << "7: Prep Socks: 15 Tokens.\n";
  181.             cout << "8: Tie Bar: 10 Tokens.\n";
  182.             cout << "9: Blue Prep Tie: 30 Tokens.\n";
  183.             cout << "10: SPP Belt: 25 Tokens.\n";
  184.         cout << "\nSelect what item you want to buy [1-10]: \n";
  185.         cin >> userChoice;
  186.         switch(userChoice) {
  187.             case 1:
  188.            
  189.                 break;
  190.         } // switch statement
  191.     } // while loop
  192. }
  193.  
  194.  
  195. // Lil God ########################################################
  196. int main() {
  197.     cout << "Prep Campus Shop_V2" << "\n==========================\n";
  198.     user();
  199.    
  200.    
  201.     return 0;
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement