Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<time.h>
- #include<ctype.h>
- #include<string.h>
- int passwordIsLongEnough(char str[])
- {
- int i, Count = 0, siffra;
- for (i = 0; str[i] != '\0'; i++)
- Count++;
- if (Count < 8)
- {
- siffra = 0;
- }
- else if (Count >= 8)
- {
- siffra = 1;
- }
- return siffra;
- }
- int passwordContainsDigit(char str[])
- {
- int i, digitCount = 0, digits;
- for (i = 0; str[i] != '\0'; i++)
- if (isdigit(str[i]))
- digitCount++;
- if (digitCount < 1)
- {
- digits = 0;
- }
- else
- {
- digits = 1;
- }
- return digits;
- }
- int passwordHasMixedCase(char str[])
- {
- char i, upper = 0, lower = 0, mixed;
- for (i = 0; str[i] != '\0'; i++)
- {
- if (isupper(str[i]))
- upper++;
- if (islower(str[i]))
- lower++;
- }
- if (upper >0 && lower >0)
- mixed = 1;
- else
- mixed = 0;
- return mixed;
- }
- int containsFourLetters(char str[])
- {
- int i, letterCount = 0, letters;
- for (i = 0; str[i] != '\0'; i++);
- {
- if (isalpha(str[i]))
- {
- letterCount++;
- }
- }
- if (letterCount < 4)
- {
- letters = 0;
- }
- else
- {
- letters = 1;
- }
- return letters;
- }
- int isSafePassword(char password[])
- {
- int length, digits, mixed, letters, SAFE;
- length = passwordIsLongEnough(password);
- digits = passwordContainsDigit(password);
- mixed = passwordHasMixedCase(password);
- letters = containsFourLetters(password);
- if (length == 1 && digits == 1 && mixed == 1 && letters==0)
- {
- SAFE = 1;
- printf("This password is safe!");
- }
- else
- {
- SAFE = 0;
- printf("Your password is not safe!");
- if (length == 0)
- {
- printf("\nYou need to have at least 8 character!");
- }
- if (digits == 0)
- {
- printf("\nYou need to have at least one digit!");
- }
- if (mixed == 0)
- {
- printf("\nYou need to have at least one small and one big letter!");
- }
- if (letters == 1)
- {
- printf("\nYou passsword contains more than 3 letters!");
- }
- }
- return SAFE;
- }
- struct account
- {
- char name[30];
- char password[30];
- char newpassword[30];
- int SAFE;
- };
- void capitalize(char Name[])
- {
- Name[0] = toupper(Name[0]);
- }
- struct account EnterAccount(void)
- {
- struct account person;
- printf("\n\nEnter your username:");
- scanf("%s", person.name);
- capitalize(person.name);
- do
- {
- do
- {
- printf("\nEnter password:");
- scanf("%s", person.password);
- person.SAFE = isSafePassword(person.password);
- } while (person.SAFE == 0);
- printf("\nEnter the same password");
- scanf("%s", person.newpassword);
- if (strcmp(person.password, person.newpassword) != 0)
- {
- printf("The passwords are not matching!");
- }
- else
- {
- printf("Your account is accepted!");
- printf("\nThe password %s is associated whith user :%s", person.password, person.name);
- }
- }while (strcmp(person.password, person.newpassword) != 0);
- return person;
- }
- int main(void)
- {
- int amount;
- int i;
- printf("How many accounts do you want to enter?");
- scanf("%d", &amount);
- account* arr = (account*)malloc(sizeof(account)*amount);
- if(arr==NULL)
- {
- printf("could not allocate %d elements!\n ", amount);
- }
- else
- {
- for (i = 0; i < amount; i++)
- {
- arr[i] = EnterAccount();
- }
- printf("\n\nUsername");
- printf("\tPassword");
- for (i = 0; i < amount; i++)
- {
- printf("\n%s", arr[i].name);
- printf("\t\t%s", arr[i].password);
- }
- free(arr);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement