Advertisement
Guest User

Untitled

a guest
Nov 12th, 2016
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. bool IsLoggedIn()
  8. {
  9. string username, password, un, pw;
  10. cout <<"Username: ";
  11. cin>>username;
  12. cout<<"Password: ";
  13. cin>>password;
  14. ifstream read("data\\" + username +".txt");
  15. getine(read, un);
  16. getline(read, pw);
  17. if(un ==username && pw==password)
  18. {
  19. return true;
  20. }
  21. else
  22. {
  23. return false;
  24. }
  25. }
  26.  
  27. int main()
  28. {
  29. int choice;
  30. cout<<"1: Register\n2: Login\nScegli: ";
  31. cin>>choice;
  32. if(choice==1)
  33. {
  34. string username, password;
  35. cout<<"Seleziona un username: ";
  36. cout<<"Seleziona una password: ";
  37. ofstream file;
  38. file.open("data\\" + username + ".txt");
  39. file<<username<<endl<<password;
  40. file.close();
  41. main();
  42. }
  43. else if(choice==2)
  44. {
  45. bool status=IsLoggedIn();
  46. if(!status)
  47. {
  48. cout<<"Login fallito!"<<endl;
  49. system("PAUSE");
  50. return 0;
  51. }
  52. else
  53. {
  54. cout<<"Loggato con successo!"<<endl;
  55. system("PAUSE");
  56. return 1;
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement