codegod313

:-)

Apr 15th, 2020
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.47 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<Windows.h>
  4. #include<fstream>
  5. #include<clocale>
  6. #include <conio.h>
  7. using namespace std;
  8.  
  9. struct person {
  10.     char login[30];
  11.     int password;
  12. };
  13.  
  14.  
  15.  
  16. int main() {
  17.     setlocale(LC_ALL, "RUS");
  18.     SetConsoleOutputCP(1251);
  19.     SetConsoleCP(1251);
  20.     cout << "Добро пожаловать в мою программу!\n1. Вход\n2. Регистрация\n3. Выход " << endl;
  21.     int choise;
  22.     cin >> choise;
  23.     string path = "myfile.txt";
  24.     fstream fout;
  25.     fout.open(path, ios::in | ios::out);
  26.     while (true)
  27.     {
  28.         switch (choise) {
  29.         case 1://вход
  30.             person second;
  31.             bool log;
  32.             log = false;
  33.             cout << "Login:";
  34.             cin >> second.login;
  35.             cout << "Password:";
  36.             cin >> second.password;
  37.             if (fout.tellg() == -1) fout.clear(ios_base::goodbit);
  38.             fout.seekg(ios::beg);
  39.             while (!fout.eof()) {//ПАМАГИТИ!!!! CodeGod is fucking here
  40.                 person peps;
  41.                 fout.read((char*)&peps, sizeof(person));
  42.                 if (strcmp(peps.login, second.login) == 0 && peps.password == second.password)
  43.                 {
  44.                     log = true;
  45.                     break;
  46.                 }
  47.             }
  48.             if (log)
  49.                 cout << "Вы вошли в систему" << endl; //Вывести сообшение
  50.             else
  51.                 cout << "Данные некорректные!" << endl; //Отказать в доступе
  52.             break;
  53.         case 2://регистрация
  54.             bool sign_in;
  55.             sign_in = false;
  56.             while (!sign_in)
  57.             {
  58.                 person first;
  59.                 cout << "Login:";
  60.                 cin >> first.login;
  61.                 cout << "Password:";
  62.                 cin >> first.password;
  63.                 if (fout.tellg() == -1) fout.clear(ios_base::goodbit);
  64.                 fout.seekg(ios_base::beg);
  65.                 bool found = false;
  66.                 while (!fout.eof())
  67.                 {
  68.                     person peps;
  69.                     fout.read((char*)&peps, sizeof(person));
  70.                     if (!strcmp(peps.login, first.login))
  71.                     {
  72.                         cout << "Такой пользоавтьель уже существует. Введите новые данные \n";
  73.                         found = true;
  74.                         break;
  75.                     }
  76.                 }
  77.                 if (!found)
  78.                 {
  79.                     fout.clear(ios_base::goodbit);
  80.                     if (fout.tellg() == 2) fout.seekg(ios_base::beg);
  81.                     sign_in = true;
  82.                     fout.write((char*)&first, sizeof(person));
  83.                     cout << "Регистрация прошла успешно \n";
  84.                 }
  85.             }
  86.             break;
  87.  
  88.         case 3:
  89.             fout.close();
  90.             return 0;
  91.             break;
  92.         default:
  93.             cout << "Неправильный выбор!" << endl;
  94.         }
  95.         cout << "1. Вход\n2. Регистрация\n3. Выход " << endl;
  96.         cin >> choise;
  97.     }
  98. }
Add Comment
Please, Sign In to add comment