Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<time.h>
  5. #include<ctype.h>
  6.  
  7. int passwordIsLoungEnough(char str[]) /*funktion 1, funkar*/
  8. {
  9. int i, counter = 0, retunera;
  10.  
  11. for (i = 0; str[i] != '\0'; i++)
  12.  
  13. counter++;
  14.  
  15. if (counter < 8)
  16. {
  17. retunera = 0;
  18. }
  19. else
  20. {
  21. retunera = 1;
  22. }
  23. return retunera;
  24. }
  25. int passwordCountainsDigit(char str[]) /* funktion 2, funkar*/
  26. {
  27. int i, counter = 0, retunera1;
  28.  
  29. for (i = 0; str[i] != '\0'; i++)
  30. if (isdigit(str[i]))
  31. counter++;
  32.  
  33. if (counter < 1)
  34. {
  35. retunera1 = 0;
  36. }
  37. else
  38. {
  39. retunera1 = 1;
  40. }
  41.  
  42.  
  43.  
  44. return retunera1;
  45. }
  46. int passwordHasMixedCase(char str[]) /*funktion 3, funkar*/
  47. {
  48. int i, upper = 0, lower = 0, retunera2;
  49.  
  50. for (i = 0; str[i] != '\0'; i++)
  51. {
  52. if (isupper(str[i]) > 0)
  53. {
  54. upper++;
  55. }
  56.  
  57. if (islower(str[i]) > 0)
  58. {
  59. lower++;
  60. }
  61.  
  62. if (upper > 0 && lower > 0)
  63. {
  64. retunera2 = 1;
  65. }
  66. else
  67. {
  68. retunera2 = 0;
  69. }
  70. }
  71. return retunera2;
  72. }
  73.  
  74. int isPasswordSafe(char password[])
  75. {
  76. int length, digit, mixedCase, retunera3;
  77.  
  78. length = passwordIsLoungEnough(password);
  79. digit = passwordCountainsDigit(password);
  80. mixedCase = passwordHasMixedCase(password);
  81.  
  82. if (length == 1 && digit == 1 && mixedCase == 1)
  83. {
  84. retunera3 = 1;
  85. }
  86. else
  87. {
  88. retunera3 = 0;
  89.  
  90.  
  91. if (length == 0)
  92. {
  93. printf("your password is not long enough.\n");
  94. }
  95. if (digit == 0)
  96. {
  97. printf("your password does not contain any digits.\n");
  98. }
  99. if (mixedCase == 0)
  100. {
  101. printf("you password does not have any mixed case letters.\n");
  102. }
  103. }
  104.  
  105. return retunera3;
  106. }
  107.  
  108.  
  109. struct account
  110. {
  111. char username[30];
  112. char password[30];
  113. char newpassword[30];
  114. int passwordcontrol;
  115. };
  116.  
  117.  
  118. struct account userAccount(void)
  119. {
  120. struct account personkonto;
  121. printf("enter a username:\n");
  122. scanf("%s", personkonto.username);
  123.  
  124. do
  125. {
  126. do
  127. {
  128. printf("enter a password:\n");
  129. scanf("%s", personkonto.password);
  130. personkonto.passwordcontrol = isPasswordSafe(personkonto.password);
  131.  
  132. } while (personkonto.passwordcontrol == 0);
  133.  
  134.  
  135. printf("\n enter the same password again\n");
  136. scanf("%s", personkonto.newpassword);
  137.  
  138.  
  139.  
  140. if (strcmp(personkonto.password, personkonto.newpassword) != 0)
  141. {
  142. printf("your passwords do not match\n");
  143. }
  144. else
  145. {
  146. printf("your password is accepted\n");
  147. }
  148.  
  149. } while (strcmp(personkonto.password, personkonto.newpassword) != 0);
  150.  
  151. printf(" your password is %s\n", personkonto.password);
  152.  
  153. return personkonto;
  154. };
  155.  
  156. int main(void)
  157. {
  158. int i, amount, namecheck = 0;
  159. char personFinder[30];
  160. printf("enter the amount of accounts:\n");
  161. scanf("%d", &amount);
  162.  
  163. account *arr = (account*)malloc(sizeof(account)*amount);
  164.  
  165. if (arr == NULL)
  166. printf("could not allocate %d elements!\n", amount);
  167. else
  168. {
  169. for (i = 0; i < amount; i++)
  170. arr[i] = userAccount();
  171. printf("username: \t \t password:\n");
  172. for (i = 0; i < amount; i++)
  173. {
  174. printf("%s \t \t %s\n", arr[i].username, arr[i].password);
  175. }
  176.  
  177. }
  178. allt under do är den uppgiften kusiner lycka till imorngon// OP
  179. do
  180. {
  181.  
  182.  
  183.  
  184. printf("enter the username of the person ur looking for:");
  185. scanf("%s", personFinder);
  186.  
  187. for (i = 0; i < amount; i++)
  188. {
  189.  
  190.  
  191. namecheck = (strcmp(arr[i].username, personFinder));
  192. if (namecheck == 0)
  193. {
  194. printf("the password associated with %s is: %s\n", personFinder, arr[i].password);
  195.  
  196. i = amount + i;
  197. }
  198.  
  199. }
  200.  
  201.  
  202.  
  203. if(namecheck >0||namecheck !=0)
  204. printf("no account with that name here\n");
  205.  
  206.  
  207.  
  208.  
  209. } while (namecheck = (strcmp(personFinder, "none") != 0));
  210.  
  211.  
  212.  
  213. free(arr);
  214. return 0;
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement