From 5b5875b3bd6a7746eae7c4887139c975e514879f Mon Sep 17 00:00:00 2001 From: anantrajputcode Date: Sun, 21 Dec 2025 13:51:52 +0530 Subject: [PATCH] Add password strength checker in C --- password_strength_checker/README.md | 80 +++++++++++++++++++ .../password-strength-checker.c | 45 +++++++++++ 2 files changed, 125 insertions(+) create mode 100644 password_strength_checker/README.md create mode 100644 password_strength_checker/password-strength-checker.c diff --git a/password_strength_checker/README.md b/password_strength_checker/README.md new file mode 100644 index 0000000..9fb8ca1 --- /dev/null +++ b/password_strength_checker/README.md @@ -0,0 +1,80 @@ +# Password Strength Checker + +A simple C program that evaluates the strength of a password based on various criteria. + +## Description + +This program analyzes a password and determines its strength based on the following factors: +- Presence of uppercase letters +- Presence of lowercase letters +- Presence of digits +- Presence of special characters +- Minimum length of 8 characters + +## Features + +- Real-time password strength evaluation +- Three strength levels: Weak, Medium, and Strong +- Simple command-line interface +- Character type detection (uppercase, lowercase, digits, special characters) + +## Compilation + +To compile the program, use any C compiler such as GCC: + +```bash +gcc password_checker.c -o password_checker +``` + +## Usage + +Run the compiled program: + +```bash +./password_checker +``` + +Enter your password when prompted. The program will analyze it and display the strength level. + +### Example + +``` +Enter your password: MyP@ss123 + +Password Strength: Strong +``` + +## Strength Criteria + +The program calculates strength based on a scoring system (0-5 points): + +- **Weak** (0-2 points): Password lacks multiple character types or is too short +- **Medium** (3-4 points): Password has good variety but may be missing some criteria +- **Strong** (5 points): Password meets all criteria including length and character variety + +### Scoring Breakdown +- 1 point: Contains uppercase letters +- 1 point: Contains lowercase letters +- 1 point: Contains digits +- 1 point: Contains special characters +- 1 point: Length is 8 or more characters + +## Limitations + +- The program uses `scanf("%s", password)` which stops at whitespace, so passwords containing spaces cannot be fully tested +- Maximum password length is limited to 99 characters +- No buffer overflow protection beyond the array size +- Doesn't check against common password lists or patterns + +## Security Note + +This is a basic educational tool for demonstrating password strength concepts. For production applications, use established password validation libraries and follow current security best practices. + +## Requirements + +- C compiler (GCC, Clang, or similar) +- Standard C library with `stdio.h`, `string.h`, and `ctype.h` + +## License + +Free to use and modify for educational purposes. \ No newline at end of file diff --git a/password_strength_checker/password-strength-checker.c b/password_strength_checker/password-strength-checker.c new file mode 100644 index 0000000..9272e16 --- /dev/null +++ b/password_strength_checker/password-strength-checker.c @@ -0,0 +1,45 @@ +#include +#include +#include + +#define MAX_PASSWORD_LENGTH 100 +#define MIN_PASSWORD_LENGTH 8 + +int main() { + char password[MAX_PASSWORD_LENGTH]; + size_t length = 0; + int upper = 0; + int lower = 0; + int digit = 0; + int special = 0; + + printf("Enter your password: "); + scanf("%99s", password); // Safe input, avoids buffer overflow + + length = strlen(password); + + for (size_t i = 0; password[i] != '\0'; i++) { + if (isupper(password[i])) { + upper = 1; + } else if (islower(password[i])) { + lower = 1; + } else if (isdigit(password[i])) { + digit = 1; + } else { + special = 1; + } + } + + int strength = upper + lower + digit + special + (length >= MIN_PASSWORD_LENGTH ? 1 : 0); + + printf("\nPassword Strength: "); + if (strength <= 2) { + printf("Weak\n"); + } else if (strength == 3 || strength == 4) { + printf("Medium\n"); + } else { + printf("Strong\n"); + } + + return 0; +} \ No newline at end of file