Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <stdlib.h>
  4. #include <string>
  5. #include <stdio.h>
  6. using namespace std;
  7.  
  8. const int AMNT=50;
  9. char filename[50];
  10. ifstream inputfile;
  11. int loginattempt =1;
  12.  
  13. typedef char mychar;
  14. mychar FirstLine[AMNT];
  15. mychar SecondLine[AMNT];
  16. mychar ThirdLine[AMNT];
  17.  
  18. struct UserRecord
  19. {
  20. string Username;
  21. string Password;
  22. char pin[20];
  23.  
  24. }a;
  25.  
  26. void wrong_input()
  27. {
  28. loginattempt =4;
  29. cout<<"Wrong input";
  30. system("pause");
  31. }
  32. void Open_Message()
  33. {
  34. cout<<"------------------------------"<<endl;
  35. cout<<"Welcome to MyGreatWebsite.com!"<<endl;
  36. cout<<"Please enter the following:"<<endl;
  37. cout<<"------------------------------"<<endl;
  38.  
  39. }
  40. void Read_Input()
  41. {
  42. //struct UserRecord a;
  43. cout<<"Username:"<<endl;
  44. cin>>a.Username;
  45. cout<<"Password:"<<endl;
  46. cin>>a.Password;
  47. cout<<"PIN:"<<endl;
  48. //cin>>a.pin;
  49. int pin;
  50. if(cin>>pin){
  51. //sprintf(a.pin, 20, "%d", pin);
  52. cout<<"======================="<<endl;
  53. cout<<"Input is "<<endl;
  54. cout<<"Username: "<<a.Username<<endl;
  55. cout<<"Password: "<<a.Password<<endl;
  56. cout<<"PIN: "<<a.pin<<endl;
  57. cout<<"======================="<<endl;
  58. }
  59. else
  60. {
  61. wrong_input();
  62.  
  63. }
  64.  
  65.  
  66. }
  67.  
  68. int main(void)
  69. {
  70.  
  71.  
  72. //struct UserRecord a;
  73. Open_Message();
  74. Read_Input();
  75.  
  76. //test open file for reading...
  77. inputfile.open("users.txt");
  78. //if not the end of file, do...
  79. if(!inputfile.eof())
  80. {
  81. //cout<<"\nThe first line of text is: \n";
  82. inputfile.getline(FirstLine, 50);
  83. // cout<<FirstLine<<'\n';
  84. // cout<<"The second line of text is: \n";
  85. inputfile.getline(SecondLine, 50);
  86. //cout<<SecondLine<<endl;
  87. //cout<<"The third line of text is: \n";
  88. inputfile.getline(ThirdLine, 50);
  89. //cout<<ThirdLine<<endl;
  90.  
  91. string z= a.pin;
  92. if (FirstLine==a.Username && SecondLine == a.Password && ThirdLine==z){ // if login data is found
  93. cout << "Successful login! Welcome " << a.Username << endl;
  94. }
  95.  
  96. else // if login data is not found
  97. {
  98. if(loginattempt<=3){
  99. cout << "\nUsername and/or password incorrect!\n\n\n\n";
  100. cout<<"Please try again"<<endl;
  101. loginattempt++;
  102. Read_Input();
  103. }
  104. else
  105. {
  106. cout << "\nUsername and/or password incorrect!\n\n\n\n";
  107. }
  108. }
  109. }
  110. system("pause");
  111. return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement