Advertisement
Guest User

Untitled

a guest
Jun 12th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <stdlib.h>
  5. #include <time.h>
  6. int passwordIsLongEnough(char str[]) /* funk.1 */
  7. {
  8.  
  9. int i;
  10. int counter = 0;
  11. int returnera;
  12. for (i = 0; str[i] != '\0'; ++i)
  13. counter++;
  14. if (counter < 8)
  15. returnera = 0;
  16. else
  17. returnera = 1;
  18. return returnera;
  19.  
  20. }
  21.  
  22. int passwordContainsDigit(char str[]) /* funk.2 */
  23. {
  24. int i, digit = 0, returnera;
  25.  
  26. for (i = 0; str[i] != '\0'; ++i)
  27. if (isdigit(str[i]))
  28. digit++;
  29. if (digit > 0)
  30.  
  31. returnera = 1;
  32.  
  33. else
  34.  
  35. returnera = 0;
  36.  
  37. return returnera;
  38. }
  39. int passwordHasMixedCase(char str[])
  40. {
  41. int i, returnera = 0, upper = 0, lower = 0;
  42. for (i = 0; str[i] != '\0'; i++)
  43. {
  44. if (islower(str[i]))
  45. {
  46. lower++;
  47. }
  48. if (isupper(str[i]))
  49. {
  50. upper++;
  51. }
  52.  
  53. if (upper > 0 && lower > 0)
  54. {
  55. returnera = 1;
  56. }
  57. else
  58. {
  59. returnera = 0;
  60. }
  61. }
  62. return returnera;
  63. }
  64. void capitalize(char Name[])
  65. {
  66.  
  67. Name[0] = toupper(Name[0]);
  68.  
  69.  
  70. }
  71.  
  72.  
  73.  
  74. int isSafePassword(char password[])
  75. {
  76. int length, digit, upperLowerCase, returnera;
  77. int faultCounter = 0;
  78. length = passwordIsLongEnough(password);
  79. digit = passwordContainsDigit(password);
  80. upperLowerCase = passwordHasMixedCase(password);
  81.  
  82. if (length == 0)
  83. {
  84. printf("Your password is not long enough, it has to be at least 8 characters \n");
  85. faultCounter++;
  86. }
  87. if (digit == 0)
  88. {
  89. printf("You password has to contain at least one digit\n");
  90. faultCounter++;
  91. }
  92. if (upperLowerCase == 0)
  93. {
  94. printf("Your password has to have at least one upper case letter and at least one lower case letter \n");
  95. faultCounter++;
  96. }
  97.  
  98. return faultCounter;
  99.  
  100. }
  101.  
  102.  
  103. struct account
  104. {
  105. char username[30];
  106. char password[30];
  107. char newPassword[30];
  108. int passwordControl;
  109.  
  110. };
  111.  
  112. struct account konto(void)
  113. {
  114. struct account userAccount;
  115.  
  116. printf("Enter a username: \n");
  117. scanf("%s", userAccount.username);
  118. capitalize(userAccount.username);
  119. do
  120. {
  121. do
  122. {
  123.  
  124. printf("Enter a password:\n");
  125. scanf("%s", userAccount.password);
  126. userAccount.passwordControl = isSafePassword(userAccount.password);
  127. if(userAccount.passwordControl>0)
  128. {
  129. printf("You have %d, faults in yur password\n", userAccount.passwordControl);
  130. }
  131.  
  132. } while (userAccount.passwordControl > 0);
  133. printf("Please confirm your password:\n");
  134. scanf("%s", userAccount.newPassword);
  135.  
  136. if (strcmp(userAccount.password, userAccount.newPassword) == 0)
  137. {
  138. printf("The password is confirmed\n");
  139. printf("The password %s is associated whith user :%s\n", userAccount.password, userAccount.username);
  140. }
  141. else
  142. printf("The passwords do not match\n");
  143. } while (strcmp(userAccount.password, userAccount.newPassword) != 0);
  144.  
  145.  
  146. return userAccount;
  147. }
  148.  
  149.  
  150. int main(void)
  151. {
  152. int antalKonton;
  153. int i;
  154.  
  155. printf("How many useraccounts do you want to enter? \n");
  156. scanf("%d", &antalKonton);
  157.  
  158. struct account* arr = (struct account*) malloc(sizeof(struct account)*antalKonton);
  159.  
  160. if (arr == NULL)
  161. printf("Could not allocate %d elements", antalKonton);
  162. else
  163. {
  164. for (i = 0; i < antalKonton; i++)
  165. {
  166. arr[i] = konto();
  167. }
  168. printf("Username: \t \t password: \n");
  169. for (i = 0; i < antalKonton; i++)
  170.  
  171. {
  172.  
  173. printf("%s \t \t %s \n", arr[i].username, arr[i].password);
  174. }
  175. free(arr);
  176.  
  177. }
  178. return 0;
  179.  
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement