Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "rlutil.h"
  4.  
  5.  
  6. void Login();
  7. void Register();
  8. char username[32];
  9. char password[32];
  10. char acc[32];
  11. char pw[32];
  12.  
  13.  
  14. int main()
  15. {
  16. int logreg;
  17. printf("Press '1' For Login");
  18. printf("Press '2' For Registern");
  19. logreg = getch();
  20. printf("n------------------------------------------------n");
  21. tester:
  22. ;
  23. if (logreg == '1')
  24. {
  25. Login();
  26. }
  27. else if (logreg == '2')
  28. {
  29. Register();
  30. }
  31. else
  32. {
  33. printf("nInvalid Input!!! Choose between '1' or '2' !!!n");
  34. logreg = getch();
  35. goto tester;
  36. }
  37. return 0;
  38. }
  39.  
  40. void Login()
  41. {
  42. start:
  43. ;
  44. char answer;
  45.  
  46. // Vnesuvanje na username
  47. printf("nEnter your Username: ");
  48. scanf("%s",username);
  49.  
  50. // Vnesuvanje na Password
  51. printf("nEnter your Password: ");
  52. scanf(" %s",password);
  53.  
  54.  
  55.  
  56.  
  57. FILE *fData;
  58. // Otvara file za citanje
  59. fData = fopen("database.txt", "rt");
  60. if (!fData)
  61. {
  62. printf("The file can not be openednaa");
  63. }
  64.  
  65. int found=0;
  66.  
  67. while(!feof(fData) && !found)
  68. {
  69. fscanf(fData, "%st%s", acc, pw);
  70. if (strcmp(username, acc) == 0 && strcmp(password, pw) == 0)
  71. {
  72. setColor(LIGHTGREEN);
  73. printf("nSuccessfuly logged it to our WebSitenn");
  74. setColor(GREY);
  75. found = 1;
  76. getch();
  77. break;
  78. }
  79. else if (!found)
  80. {
  81. setColor(LIGHTRED);
  82. printf("nNo Access to our WebSitenn");
  83. printf("Invalid username or password!!!nn");
  84. setColor(GREY);
  85. printf("Would you like to try again?? [y/n] ");
  86. answer = getch();
  87. found = 0;
  88. printf("nn------------------------------------------------n");
  89. break;
  90. }
  91. }
  92.  
  93. fclose(fData);
  94.  
  95. tester2:
  96. ;
  97. //proverka za Povtorno pustanje na programata
  98. if (answer== 'y')
  99. {
  100. goto start;
  101. }
  102. else
  103. {
  104. if (answer!='n')
  105. {
  106. printf("Please choose between 'y' or 'n' !!!nn");
  107. answer = getch();
  108. goto tester2;
  109. }
  110. else
  111. {
  112. getch();
  113. return 0;
  114. }
  115. }
  116.  
  117. }
  118.  
  119. void Register()
  120. {
  121. char acc[32];
  122. char pw[32];
  123. FILE *fData;
  124. fData = fopen("database.txt", "a");
  125. if (!fData)
  126. {
  127. printf("File could not be openednaa");
  128. getchar();
  129. return;
  130. }
  131. printf("Enter your desired Username: ");
  132. scanf("%s", acc);
  133. printf("Enter your desired Password: ");
  134. scanf("%s", pw);
  135. printf("n");
  136. fprintf(fData, "%st%sn", acc, pw);
  137. fclose(fData);
  138. }
  139.  
  140. FILE *fData;
  141. // Otvara file za citanje
  142. fData = fopen("database.txt", "rt");
  143. if (!fData)
  144. {
  145. printf("The file can not be openednaa");
  146. }
  147.  
  148. int found=0;
  149.  
  150. while(!feof(fData) && !found)
  151. {
  152. fscanf(fData, "%st%s", acc, pw);
  153. if (strcmp(username, acc) == 0 && strcmp(password, pw) == 0)
  154. {
  155. setColor(LIGHTGREEN);
  156. printf("nSuccessfuly logged it to our WebSitenn");
  157. setColor(GREY);
  158. found = 1;
  159. getch();
  160. break;
  161. }
  162. else if (!found)
  163. {
  164. setColor(LIGHTRED);
  165. printf("nNo Access to our WebSitenn");
  166. printf("Invalid username or password!!!nn");
  167. setColor(GREY);
  168. printf("Would you like to try again?? [y/n] ");
  169. answer = getch();
  170. found = 0;
  171. printf("nn------------------------------------------------n");
  172. break;
  173. }
  174. }
  175.  
  176. fclose(fData);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement