Advertisement
deathkostis

Untitled

Jan 5th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char* registeredClientDatabase[50][12];
  6. char* pendingClientDatabase[50];
  7. char empty[50] = "null";
  8.  
  9. void adminLogin();
  10. void clientRegister();
  11. char passwordConversion(char username[50]);
  12.  
  13.  
  14. int main(int argc, char *argv[]){
  15.  
  16. char selection[50];
  17.  
  18. char action[50];
  19. int i, j;
  20.  
  21. for(i = 0; i < 50; i++)
  22. {
  23. for(j = 0; j < 12; j++)
  24. {
  25. registeredClientDatabase[i][j] = empty;
  26. }
  27. }
  28.  
  29. for(i = 0; i < 50; i++)
  30. {
  31. for(j = 0; j < 2; j++)
  32. {
  33. pendingClientDatabase[i][j] = empty;
  34. }
  35. }
  36.  
  37. do
  38. {
  39.  
  40. printf("Welcome to the Home Screen");
  41.  
  42. do
  43. {
  44. printf("What would you like to log in as?\n");
  45. printf("Please type 'Admin' to log in as an admin: \n");
  46. printf("Please type 'Client' to log in as a client: \n");
  47. scanf(" %s", &selection);
  48. }
  49. while((strcmp(selection, "Admin") != 0) || (strcmp(selection, "Client") != 0));
  50.  
  51. if(strcmp(selection, "Admin") == 0)
  52. {
  53. printf("Welcome to the admins' login screen: \n");
  54.  
  55. adminLogin();
  56.  
  57. do
  58. {
  59.  
  60. }
  61. while(strcmp(action, "Exit") != 0);
  62. }
  63. else
  64. {
  65. printf("Welcome to the clients' login screen: \n");
  66.  
  67. char clientAction[50];
  68.  
  69. do
  70. {
  71. printf("Would you like to Login or Register? \n");
  72. printf("Please type 'Login' to login: \n");
  73. printf("Please type 'Register' to register: \n");
  74. scanf(" %s", &clientAction);
  75. }
  76. while((strcmp(clientAction, "Login") != 0) || (strcmp(clientAction, "Register") != 0));
  77.  
  78. if(strcmp(clientAction, "Register") == 0)
  79. {
  80. clientRegister();
  81. }
  82. else
  83. {
  84. int loginFlag = 0;
  85. char registerUsername[50];
  86.  
  87. printf("Please type in your username: \n");
  88. scanf(" %s", &registerUsername);
  89.  
  90. for(i = 0; i < 50; i++)
  91. {
  92. if(strcmp(registerUsername, registeredClientDatabase[i][1]) == 0)
  93. {
  94. loginFlag = 1;
  95. registeredClientDatabase[i][2] = passwordConversion(registerUsername);
  96. }
  97. }
  98.  
  99. if(loginFlag = 1)
  100. {
  101.  
  102. }
  103. else
  104. {
  105. printf("We're sorry but the username that you have provided does not exist in our database of registered clients \n");
  106. }
  107. }
  108.  
  109. }
  110. }
  111. while(strcmp(action, "Skata") != 0);
  112.  
  113. return 0;
  114. }
  115.  
  116. void adminLogin()
  117. {
  118. char username[50];
  119. char password[50];
  120.  
  121. do
  122. {
  123. printf("Please provide the admin's username: \n");
  124. scanf(" %s", &username);
  125. }
  126. while(strcmp(username, "admin") != 0);
  127.  
  128. do
  129. {
  130. printf("Please provide the admin's password: \n");
  131. scanf(" %s", &password);
  132. }
  133. while(strcmp(password, "pizza") != 0);
  134. }
  135.  
  136. void clientRegister()
  137. {
  138. char username[50];
  139. int flag;
  140. int i;
  141.  
  142. do
  143. {
  144. flag = 1;
  145. printf("Please choose your username: \n");
  146. scanf(" %s", &username);
  147.  
  148. for(i = 0; i < 50; i++)
  149. {
  150. if((strcmp(username, pendingClientDatabase[i]) == 0) || (strcmp(username, registeredClientDatabase[i][1]) == 0))
  151. {
  152. flag = 0;
  153. }
  154. }
  155. }
  156. while(flag == 0);
  157.  
  158. for(i = 0; i < 50; i++)
  159. {
  160. if((flag == 1) && (strcmp(pendingClientDatabase[i], empty) == 0))
  161. {
  162. pendingClientDatabase[i] = username;
  163. flag = 0;
  164. }
  165. }
  166. }
  167.  
  168. char passwordConversion(char username[50])
  169. {
  170. char lowerCaseLetters[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
  171. char CapsLetters[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
  172.  
  173. char password[50];
  174. int i = 0, j =0;
  175. int letterCheck = 3;
  176.  
  177. while(username[i] != '\0')
  178. {
  179. for(j = 0; j < 26; j++)
  180. {
  181. if(username[i] == lowerCaseLetters[j])
  182. {
  183. if(letterCheck % 2 == 1)
  184. {
  185. password[i] = CapsLetters[j];
  186. }
  187. else
  188. {
  189. password[i] = lowerCaseLetters[j];
  190. }
  191. letterCheck = letterCheck + 1;
  192. }
  193. }
  194. }
  195.  
  196. return password;
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement