Guest User

Untitled

a guest
Jan 5th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<string.h>
  4. #include<unistd.h>
  5. #include<termios.h>
  6. using namespace std;
  7. int getch() {
  8. struct termios oldt, newt;
  9. int ch;
  10. tcgetattr(STDIN_FILENO, &oldt);
  11. newt = oldt;
  12. newt.c_lflag &= ~(ICANON | ECHO);
  13. tcsetattr(STDIN_FILENO, TCSANOW, &newt);
  14. ch = getchar();
  15. tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
  16. return ch;
  17. }
  18. bool authUser();
  19. class user{
  20. char uid[8];
  21. char pwd[8];
  22. int level;
  23. public:
  24. void initUser(){
  25. cout<<"\nUsername(7ch max): ";
  26. cin.getline(uid, 7);
  27. cout<<"Password(7ch max): ";
  28. cin.getline(pwd, 7);
  29. level = 0;
  30. }
  31. int authenticate(char *u, char *p){
  32. if((!strcmp(u, uid)) && (!strcmp(p, pwd)))
  33. return 1;
  34. else if(!strcmp(u, uid))
  35. return 0;
  36. else
  37. return -1;
  38. }
  39. void _debug(){
  40. cout<<uid<<"|"<<pwd<<"|"<<level;
  41. }
  42. char* getData(int f){
  43. if(f)
  44. return uid;
  45. return pwd;
  46. }
  47. int getLevel(){
  48. return level;
  49. }
  50. }CURRENT;
  51. void addUser(){
  52. cout<<"\n==========================================================================="
  53. <<"\n CTC UserDB V1.0";
  54. user newUser, t;
  55. newUser.initUser();
  56. fstream userdb;
  57. userdb.open("users.ctc", ios::binary|ios::in);
  58. while(!userdb.eof()){
  59. userdb.read((char*)&t, sizeof(t));
  60. if(!strcmp(newUser.getData(1), t.getData(1))){
  61. cout<<"\nUser already exist, please redo\n";
  62. userdb.close();
  63. addUser();
  64. }
  65. }
  66. userdb.close();
  67. userdb.open("users.ctc", ios::binary|ios::out|ios::app);
  68. userdb.write((char*)&newUser, sizeof(newUser));
  69. cout<<"\n User Successfully created";
  70. userdb.close();
  71. authUser();
  72. }
  73. bool authUser(){
  74. char u[8],p[8],x;
  75. int i=0;
  76. cout<<"\n==========================================================================="
  77. <<"\n CTC UserAuth V1.1a";
  78. cout<<"\nUSERNAME : ";cin.getline(u, 7);
  79. cout<<"PASSWORD : ";
  80. do{
  81. x = getch();
  82. p[i] = x;
  83. if(x == '\n'){
  84. p[i]='\0';
  85. break;
  86. }
  87. cout<<"*";
  88. i++;
  89. }while(i<8);
  90. user t;
  91. fstream userdb;
  92. userdb.open("users.ctc", ios::binary|ios::in);
  93. while(!userdb.eof()){
  94. userdb.read((char*)&t, sizeof(t));
  95. if(t.authenticate(u, p) == 1){
  96. CURRENT = t;
  97. cout<<"\n Logged in successfully as "<<CURRENT.getData(1);
  98. userdb.close();
  99. return true;
  100. }
  101. else if(t.authenticate(u, p) == 0){
  102. cout<<"\nWrong password, please login again.";
  103. userdb.close();
  104. return authUser();
  105. }
  106. }
  107. cout<<"\nInvalid login data, please login again";
  108. return authUser();
  109. }
  110. int main(){
  111. char ch;
  112. cout<<"8\"\"\"\"8 \"\"8\"\" 8\"\"\"\"8\n8 \" eeeee eeeee eeee e e 8 e e eeee 8 \" eeeee eeeee eeee\n8e 8 8 8 8 8 8 8 8 8e 8 8 8 8e 8 88 8 8 8\n88 8eee8e 8eee8 8e 8eee8e 88 8eee8 8eee 88 8 8 8e 8 8eee\n88 e 88 8 88 8 88 88 8 88 88 8 88 88 e 8 8 88 8 88\n88eee8 88 8 88 8 88e8 88 8 88 88 8 88ee 88eee8 8eee8 88ee8 88ee\n";
  113. cout<<"\n==========================================================================="
  114. <<"\n Crack The Code V0.1b"
  115. <<"\n1)Login\n2)Create"
  116. <<"\n$ ";
  117. cin>>ch;
  118. cin.ignore();
  119. if(ch == '1')
  120. authUser();
  121. else
  122. addUser();
  123. cout<<"\n==========================================================================="
  124. <<"\nHello "<<CURRENT.getData(1)<<", you are currently on Level "<<CURRENT.getLevel()<<".\nContinue playing now? (y)es or (n)o";
  125. }
Add Comment
Please, Sign In to add comment