rohit35

in files

Mar 30th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.03 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<conio.h>
  4. #include<string.h>
  5. #define space "\t \t \t"
  6. typedef struct File2
  7. {
  8. void *portfolio;
  9. void *watchlist;
  10. void *account;
  11. void *transaction histroy;
  12. } user_t;
  13. void userpage(char *users);
  14. void userpage(char *users)
  15. {
  16. int max=5,select=1;
  17. while(1)
  18. {
  19. system("cls");
  20. system("color 07");
  21.  
  22. }
  23. }
  24. int main()
  25. {
  26. system("color 04");
  27. printf("WELCOME\n");
  28. printf(" TO \n");
  29. printf(" HELIX \n");
  30. printf("Press any Key\n");
  31. _getch();
  32. char users[100];
  33. if(Main_page(users)==0)
  34. {
  35. userpage(users);
  36. }
  37. else
  38. {
  39. printf("\nThank you for visiting\n");
  40. }
  41. return 0;
  42. }
  43. int Main_page(char *users)
  44. {
  45. FILE *fp;
  46. char choice,x;
  47. char username[100];
  48. char password[100];
  49. int i=0;
  50. main_sec:
  51. system("cls");
  52. while(1)
  53. {
  54. printf("Helix\n");
  55. printf("1)login\n");
  56. printf("2)signup\n");
  57. printf("3)exit");
  58. choice=_getch();
  59. if(choice== 49 || choice ==50 ||choice==51)
  60. break;
  61. else
  62. {
  63. printf("Enter valid choice\n");
  64. }
  65. }
  66. if(choice==49)
  67. {
  68. char x,*tempstr;
  69. char accountsDB[100];
  70. system("cls");
  71. printf("Login \n");
  72. printf("Username:");
  73. scanf("%s",username);
  74. printf("\n");
  75. i=0;
  76. while(username[i] != '\0')
  77. {
  78. users[i] = username[i];
  79. i++;
  80. }
  81. users[i] = '\0';
  82. i=0;
  83. printf("Password:");
  84. while ((x = _getch()) != '\r')
  85. {
  86. printf("*");
  87. password[i++] = x;
  88. }
  89. password[i] = '\0';
  90. i = 0;
  91. strcat(username, password);
  92. fp = fopen("PROJECT_DATA_FILE.txt","r");
  93. while((x = fgetc(fp)) != EOF)
  94. {
  95. accountsDB[i++] = x;
  96. }
  97. accountsDB[i] = '\0';
  98. fclose(fp);
  99. if(NULL == strstr(accountsDB, username))
  100. {
  101. printf("\n\n"space space"*Username or password is wrong");
  102. _getch();
  103. goto main_sec;
  104. }
  105. else
  106. {
  107. tempstr = strstr(accountsDB, username);
  108. }
  109. i=0;
  110. while(username[i]!='\0')
  111. {
  112. if(username[i]!=tempstr[i])
  113. break;
  114.  
  115. i++;
  116. }
  117. if(i==strlen(username))
  118. {
  119. return 0;
  120. }
  121. else
  122. {
  123. printf("\n\n*Username or password is wrong");
  124. _getch();
  125. goto main_sec;
  126. }
  127. }
  128. if(choice ==50)
  129. {
  130. system("cls");
  131. printf("Signup\n");
  132. printf("Username:");
  133. scanf("%s",username);
  134. i=0;
  135. while((x = username[i]) != '\0')
  136. {
  137. if(x == '|' || x == '#' || x == '$')
  138. {
  139. printf("\n*Username must not contain special characters like |, #, $ etc.");
  140. _getch();
  141. goto main_sec;
  142. }
  143. i++;
  144. }
  145. char accountsDB[100];
  146. fp = fopen("PROJECT_DATA_FILE.txt","r");
  147. i = 0;
  148. while((x = fgetc(fp)) != EOF)
  149. {
  150. accountsDB[i++] = x;
  151. }
  152. fclose(fp);
  153. char temp_pass[100];
  154. if(NULL == strstr(accountsDB, username))
  155. {
  156. i=0;
  157. printf("Password:");
  158. while ((x = _getch()) != '\r')
  159. {
  160. printf("*");
  161. password[i++] = x;
  162. }
  163. password[i] = '\0';
  164. printf("\nRe-Enter password:");
  165. i = 0;
  166. while((x = _getch()) != '\r')
  167. {
  168. printf("*");
  169. temp_pass[i++] = x;
  170. }
  171. temp_pass[i]='\0';
  172. if(strcmp(temp_pass,password)==0)
  173. {
  174. i = 0;
  175. fp = fopen("PROJECT_DATA_FILE.txt","a");
  176. fputc('|',fp);
  177. while((x = username[i]) != '\0')
  178. {
  179. fputc(x,fp);
  180. i++;
  181. }
  182. i = 0;
  183. while((x = password[i]) != '\0')
  184. {
  185. fputc(x,fp);
  186. i++;
  187. }
  188. fputc('$', fp);
  189. fputc('1', fp);
  190. fputc('#', fp);
  191. fputc('1', fp);
  192. fclose(fp);
  193. printf("\n\nSign up successful");
  194. _getch();
  195. goto main_sec;
  196. }
  197. else
  198. {
  199. printf("\n\n*Passwords do not match, try again");
  200. _getch();
  201. goto main_sec;
  202. }
  203. }
  204. else
  205. {
  206. printf("\n*Username is already taken");
  207. _getch();
  208. goto main_sec;
  209. }
  210. }
  211. if(choice==51)
  212. {
  213. fclose(fp);
  214. return 1;
  215. }
  216. }
Add Comment
Please, Sign In to add comment