Advertisement
Guest User

Untitled

a guest
May 3rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<string>
  4. using namespace std;
  5. void login()
  6. {
  7. char npass[10];
  8. int i = 0;
  9. char user[10], name[10], newpass[10], oldpass[10];
  10. cout << "Enter user name: ";
  11. cin >> user;
  12. cout << "Enter password: ";
  13. ifstream file ("password.txt");
  14. if (file.is_open())
  15. {
  16. std::getline(file, name);
  17. std::getline(file, oldpass);
  18. if ((user == name) & (newpass == oldpass))
  19. cout << "Login successful!!!" << endl;
  20. else
  21. cout << "Wrong user name or password!!!" << endl;
  22. }
  23. cin.ignore();
  24. }
  25. int menu()
  26. {
  27. int opt;
  28. do{
  29. cout << "1: Login\n2: Exit\nEnter an option: ";
  30. cin >> opt;
  31. switch(opt)
  32. {
  33. case 1: login(); break;
  34. case 2: break;
  35. }
  36. }while(opt != 2);
  37. return 0;
  38. }
  39. void newuser()
  40. {
  41. char pass[10];
  42. int i = 0;
  43. char name[10];
  44. cout << "Welcome new user---" << endl
  45. << "Enter user name: ";
  46. cin >> name;
  47. cout << "Enter new password(6 characters): ";
  48. while(i < 6)
  49. {
  50. pass[i] = getch();
  51. cout << "*";
  52. i++;
  53. }
  54. cout << endl;
  55. ofstream file ("password.txt");
  56. file << name << endl;
  57. while (i < 6)
  58. {
  59. file << pass[i];
  60. i++;
  61. }
  62. file << '"' << endl;
  63. file.close();
  64. menu();
  65. }
  66. int main()
  67. {
  68. ifstream file ("password.txt");
  69. file.open ("password.txt");
  70. if (file.is_open())
  71. menu();
  72. else
  73. newuser();
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement