Advertisement
notjacob

C++ multi user login system (improved but w/ errors)

Dec 2nd, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6.     vector <string> accinfo = {"admin admin"};
  7.     string hpass;
  8.     string hem;
  9.     string hacc;
  10.     string hem2;
  11.     string hpass2;
  12.     int hid2;
  13.     string hacc2;
  14.     int hid;
  15.    
  16.     int ch = 0;
  17.     int loop = 1;
  18.    while (loop == 1) {
  19.     loop = 0;
  20.     cout << "Welcome to the website!\n\nWould you like to\n1. login\n2. register\n";
  21.     cin >> ch;
  22.    
  23.     if (ch == 2) {
  24.         cout << "Thank you for regsistering with us!\n\nPlease enter an email:\n";
  25.         cin >> hem;
  26.         cout << "Please enter a password:\n";
  27.         cin >> hpass;
  28.         hacc = hem + " " + hpass;
  29.         accinfo.push_back(hpass);
  30.         cout << "Registration complete!\n";
  31.         hid = accinfo.size() + 1;
  32.         cout << "Your id is " << hid << "\n";
  33.         cout << accinfo.size();
  34.         loop = 1;
  35.     }
  36.     else if (ch == 1) {
  37.         cout << "Please enter your id:\n";
  38.         cin >> hid2;
  39.         hid2 = hid2 - 1;
  40.         cout << "Please enter your email:\n";
  41.         cin >> hem2;
  42.         cout << "Please enter your password:\n";
  43.         cin >> hpass2;
  44.         hacc2 = hem2 + " " + hpass2;
  45.         if (hacc2 == accinfo[hid2]) {
  46.             cout << "Login succesful!\n";
  47.             return 0;
  48.         }
  49.         else if (hacc2 != accinfo[hid2]) {
  50.             cout << "Login failed! Invalid ID?\n";
  51.             loop = 1;
  52.         }
  53.        
  54.     }
  55.     else {
  56.         cout << "Invalid option\n";
  57.         loop = 1;
  58.        
  59.     }
  60.    }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement