Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #include<time.h>
- #include<ctype.h>
- int passwordIsLoungEnough(char str[]) /*funktion 1, funkar*/
- {
- int i, counter = 0, retunera;
- for (i = 0; str[i] != '\0'; i++)
- counter++;
- if (counter < 8)
- {
- retunera = 0;
- }
- else
- {
- retunera = 1;
- }
- return retunera;
- }
- int passwordCountainsDigit(char str[]) /* funktion 2, funkar*/
- {
- int i, counter = 0, retunera1;
- for (i = 0; str[i] != '\0'; i++)
- if (isdigit(str[i]))
- counter++;
- if (counter<1)
- {
- retunera1 = 0;
- }
- else
- {
- retunera1 = 1;
- }
- return retunera1;
- }
- int passwordHasMixedCase(char str[]) /*funktion 3, funkar*/
- {
- int i, upper=0,lower=0, retunera2;
- for (i = 0; str[i] != '\0'; i++)
- {
- if (isupper(str[i])>0)
- {
- upper++;
- }
- if (islower(str[i]) > 0)
- {
- lower++;
- }
- if (upper >0 && lower >0)
- {
- retunera2 = 1;
- }
- else
- {
- retunera2 = 0;
- }
- }
- return retunera2;
- }
- int startsWithLetter(char str[])
- {
- int i, bokstav = 0, retunera4;
- for (i = 0; i <1; i++)
- {
- if (isalpha(str[i]) > 0)
- bokstav++;
- if (bokstav > 0)
- {
- retunera4 = 1;
- }
- if(bokstav==0)
- {
- retunera4 = 0;
- }
- }
- return retunera4;
- }
- int isPasswordSafe(char password[])
- {
- int length, digit, mixedCase, retunera3, bokstavStart;
- length = passwordIsLoungEnough(password);
- digit = passwordCountainsDigit(password);
- mixedCase = passwordHasMixedCase(password);
- bokstavStart = startsWithLetter(password);
- if (length == 1 && digit == 1 && mixedCase == 1&& bokstavStart==0)
- {
- retunera3 = 1;
- }
- else
- {
- retunera3 = 0;
- if (length == 0)
- {
- printf("your password is not long enough.\n");
- }
- if (digit == 0)
- {
- printf("your password does not contain any digits.\n");
- }
- if (mixedCase == 0)
- {
- printf("you password does not have any mixed case letters.\n");
- }
- if (bokstavStart == 1)
- {
- printf("you password starts with a Letter and that is not allowed\n");
- }
- }
- return retunera3;
- }
- struct account
- {
- char username[30];
- char password[30];
- char newpassword[30];
- int passwordcontrol;
- };
- struct account userAccount(void)
- {
- struct account personkonto;
- printf("enter a username:\n");
- scanf("%s", personkonto.username);
- do
- {
- do
- {
- printf("enter a password:\n");
- scanf("%s", personkonto.password);
- personkonto.passwordcontrol = isPasswordSafe(personkonto.password);
- } while (personkonto.passwordcontrol == 0);
- printf("\n enter the same password again\n");
- scanf("%s", personkonto.newpassword);
- if (strcmp(personkonto.password, personkonto.newpassword) != 0)
- {
- printf("your passwords do not match\n");
- }
- else
- {
- printf("your password is accepted\n");
- }
- } while (strcmp(personkonto.password, personkonto.newpassword) != 0);
- printf(" your password is %s\n", personkonto.password);
- return personkonto;
- };
- int main(void)
- {
- int i, amount, namecheck = 0;
- char personFinder[30];
- printf("enter the amount of accounts:\n");
- 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] = userAccount();
- }
- do
- {
- printf("enter the username of the person ur looking for:(type none to exit if you are not looking for any ones password):");
- scanf("%s", personFinder);
- for (i = 0; i < amount; i++)
- {
- namecheck = (strcmp(arr[i].username, personFinder));
- if (namecheck == 0)
- {
- printf("the password associated with %s is: %s\n", personFinder, arr[i].password);
- i = amount + i;
- }
- }
- if (namecheck > 0 || namecheck != 0)
- printf("no account with that name here\n");
- } while (namecheck = (strcmp(personFinder, "none") != 0));
- free(arr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement