Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. struct account {
  2. string login;
  3. string pass;
  4. bool admin;
  5. };
  6.  
  7. bool auth() {
  8. account user;
  9. account input;
  10. ifstream fin("users.bin", ios::binary | ios::in);
  11.  
  12. if (fin.is_open()) {
  13. while (true) {
  14. system("cls");
  15. cout << "login: ";
  16. getline(cin, input.login);
  17. cout << "pass: ";
  18. getline(cin, input.pass);
  19.  
  20. while (!fin.eof()) {
  21. fin.read((char*)&user, sizeof(user));
  22.  
  23. if (input.login == user.login && input.pass == user.pass) {
  24. fin.close();
  25. system("cls");
  26. cout << "hello, " << user.login << "n" << endl;
  27. cout << "press any key...";
  28. _getwch();
  29.  
  30. return user.admin;
  31. }
  32. }
  33. system("cls");
  34. cout << "Incorrect login or passwordn" << endl;
  35. cout << "press any key...";
  36. _getwch();
  37.  
  38. fin.clear();
  39. fin.seekg(0, ios::beg);
  40. }
  41. }
  42. else {
  43. cout << "File is not avalible" << endl;
  44. abort();
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement