Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdlib.h>
- #include <time.h>
- int passwordIsLongEnough(char str[]) /* funk.1 */
- {
- int i;
- int counter = 0;
- int returnera;
- for (i = 0; str[i] != '\0'; ++i)
- counter++;
- if (counter < 8)
- returnera = 0;
- else
- returnera = 1;
- return returnera;
- }
- int passwordContainsDigit(char str[]) /* funk.2 */
- {
- int i, digit = 0, returnera;
- for (i = 0; str[i] != '\0'; ++i)
- if (isdigit(str[i]))
- digit++;
- if (digit > 0)
- returnera = 1;
- else
- returnera = 0;
- return returnera;
- }
- int passwordHasMixedCase(char str[])
- {
- int i, returnera = 0, upper = 0, lower = 0;
- for (i = 0; str[i] != '\0'; i++)
- {
- if (islower(str[i]))
- {
- lower++;
- }
- if (isupper(str[i]))
- {
- upper++;
- }
- if (upper > 0 && lower > 0)
- {
- returnera = 1;
- }
- else
- {
- returnera = 0;
- }
- }
- return returnera;
- }
- void capitalize(char Name[])
- {
- Name[0] = toupper(Name[0]);
- }
- int isSafePassword(char password[])
- {
- int length, digit, upperLowerCase, returnera;
- int faultCounter = 0;
- length = passwordIsLongEnough(password);
- digit = passwordContainsDigit(password);
- upperLowerCase = passwordHasMixedCase(password);
- if (length == 1 && digit == 1 && upperLowerCase == 1)
- {
- returnera = 1;
- }
- else
- {
- returnera = 0;
- }
- if (length == 0)
- {
- printf("Your password is not long enough, it has to be at least 8 characters \n");
- faultCounter++;
- }
- if (digit == 0)
- {
- printf("You password has to contain at least one digit\n");
- faultCounter++;
- }
- if (upperLowerCase == 0)
- {
- printf("Your password has to have at least one upper case letter and at least one lower case letter \n");
- faultCounter++;
- }
- if (faultCounter > 0)
- {
- printf("You have %d, faults in yur password\n", faultCounter);
- }
- return returnera;
- }
- struct account
- {
- char username[30];
- char password[30];
- char newPassword[30];
- int passwordControl;
- };
- struct account konto(void)
- {
- struct account userAccount;
- printf("Enter a username: \n");
- scanf("%s", userAccount.username);
- capitalize(userAccount.username);
- do
- {
- do
- {
- printf("Enter a password:\n");
- scanf("%s", userAccount.password);
- userAccount.passwordControl = isSafePassword(userAccount.password);
- } while (userAccount.passwordControl == 0);
- printf("Please confirm your password:\n");
- scanf("%s", userAccount.newPassword);
- if (strcmp(userAccount.password, userAccount.newPassword) == 0)
- {
- printf("The password is confirmed\n");
- printf("The password %s is associated whith user :%s\n", userAccount.password, userAccount.username);
- }
- else
- printf("The passwords do not match\n");
- } while (strcmp(userAccount.password, userAccount.newPassword) != 0);
- return userAccount;
- }
- int main(void)
- {
- int antalKonton;
- int i;
- printf("How many useraccounts do you want to enter? \n");
- scanf("%d", &antalKonton);
- struct account* arr = (struct account*) malloc(sizeof(struct account)*antalKonton);
- if (arr == NULL)
- printf("Could not allocate %d elements", antalKonton);
- else
- {
- for (i = 0; i < antalKonton; i++)
- {
- arr[i] = konto();
- }
- printf("Username: \t \t password: \n");
- for (i = 0; i < antalKonton; i++)
- {
- printf("%s \t \t %s \n", arr[i].username, arr[i].password);
- }
- free(arr);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement