Advertisement
Guest User

Untitled

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