Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <stdlib.h>
  4. #include <fstream>
  5. #include<conio.h>
  6. #include<windows.h>
  7. #include<iomanip>
  8. using namespace std;
  9. bool login();
  10. void studlog();
  11. void reginput();
  12.  
  13.  
  14. int main(){
  15.  
  16.  
  17. studlog();
  18. cout<<"Program starts here";
  19. }
  20. void studlog(){
  21. bool on=true;
  22. int choice;
  23. while (on != false){
  24. cout << " S T U D E N T L O G I N\n";
  25. cout << "*******************************\n";
  26. cout << " 1 - Login.\n";
  27. cout << " 2 - Register.\n";
  28. cout << " 3 - Exit.\n";
  29. cout << "*******************************\n";
  30. cin>> choice;
  31. switch (choice)
  32. {
  33. case 1:
  34. system("cls");
  35. on = login();
  36. system("pause");
  37. system("cls");
  38. break;
  39.  
  40. case 2:
  41. system("cls");
  42. reginput();
  43. system("pause");
  44. system("cls");
  45. break;
  46.  
  47. case 3:
  48. on= false;
  49. break;
  50. }
  51. }
  52.  
  53. }
  54.  
  55. void reginput(){
  56. string regUser, regPass;
  57. cout<<"Username:";
  58. cin>>regUser;
  59. cout<<"Password:";
  60. cin>>regPass;
  61.  
  62. ofstream file;
  63. file.open(regUser.c_str());
  64. file <<regUser<<endl<<regPass;
  65. file.close();
  66. }
  67.  
  68. bool login(){
  69. string logUser;
  70. string logPass;
  71. string pass;
  72. string usern;
  73. cout<<"Enter Username: ";
  74. cin>> logUser;
  75. cout<<"Enter Password: ";
  76. cin>> logPass;
  77.  
  78. ifstream read(logUser.c_str());
  79. getline(read, usern);
  80. getline(read, pass);
  81.  
  82. if (usern == logUser && pass==logPass){
  83. cout << "You have been logged in!"<<endl;
  84. return false;
  85. }
  86.  
  87. else{
  88. cout << "Invalid username or id!"<<endl;
  89. return true;
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement