Password Checker
Quick Lowery Offices is still having password issues, we need you to write another program.
This program must be able to:
- Accept the input of a password
- Return a message to say if the password has passed or not
- Check for any repeating patterns, if any are found then the password will fails
Examples of failing passwords;
- Banana
- Cheese
Examples of successful passwords:
- BaNana
- Che3se
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
bool checkRepeatingPatterns(char password[]) {
int length = strlen(password);
for (int patternSize = 1; patternSize <= length / 2; patternSize++) {
for (int i = 0; i <= length - 2 * patternSize; i++) {
bool isRepeated = true;
for (int j = i; j < i + patternSize; j++) {
if (password[j] != password[j + patternSize]) {
isRepeated = false;
break;
}
}
if (isRepeated) {
return true;
}
}
}
return false;
}
int main() {
char password[50];
printf("Enter your password: ");
scanf("%s", password);
if (checkRepeatingPatterns(password)) {
printf("Password failed. Repeating patterns detected.\n");
} else {
printf("Password passed. No repeating patterns found.\n");
}
return 0;
}