Skip to content

Commit 7fe92c3

Browse files
Add password strength checker in C
1 parent fc6ca57 commit 7fe92c3

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Password Strength Checker
2+
3+
A simple C program that evaluates the strength of a password based on various criteria.
4+
5+
## Description
6+
7+
This program analyzes a password and determines its strength based on the following factors:
8+
- Presence of uppercase letters
9+
- Presence of lowercase letters
10+
- Presence of digits
11+
- Presence of special characters
12+
- Minimum length of 8 characters
13+
14+
## Features
15+
16+
- Real-time password strength evaluation
17+
- Three strength levels: Weak, Medium, and Strong
18+
- Simple command-line interface
19+
- Character type detection (uppercase, lowercase, digits, special characters)
20+
21+
## Compilation
22+
23+
To compile the program, use any C compiler such as GCC:
24+
25+
```bash
26+
gcc password_checker.c -o password_checker
27+
```
28+
29+
## Usage
30+
31+
Run the compiled program:
32+
33+
```bash
34+
./password_checker
35+
```
36+
37+
Enter your password when prompted. The program will analyze it and display the strength level.
38+
39+
### Example
40+
41+
```
42+
Enter your password: MyP@ss123
43+
44+
Password Strength: Strong
45+
```
46+
47+
## Strength Criteria
48+
49+
The program calculates strength based on a scoring system (0-5 points):
50+
51+
- **Weak** (0-2 points): Password lacks multiple character types or is too short
52+
- **Medium** (3-4 points): Password has good variety but may be missing some criteria
53+
- **Strong** (5 points): Password meets all criteria including length and character variety
54+
55+
### Scoring Breakdown
56+
- 1 point: Contains uppercase letters
57+
- 1 point: Contains lowercase letters
58+
- 1 point: Contains digits
59+
- 1 point: Contains special characters
60+
- 1 point: Length is 8 or more characters
61+
62+
## Limitations
63+
64+
- The program uses `scanf("%s", password)` which stops at whitespace, so passwords containing spaces cannot be fully tested
65+
- Maximum password length is limited to 99 characters
66+
- No buffer overflow protection beyond the array size
67+
- Doesn't check against common password lists or patterns
68+
69+
## Security Note
70+
71+
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.
72+
73+
## Requirements
74+
75+
- C compiler (GCC, Clang, or similar)
76+
- Standard C library with `stdio.h`, `string.h`, and `ctype.h`
77+
78+
## License
79+
80+
Free to use and modify for educational purposes.
33 KB
Binary file not shown.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
#include <ctype.h>
4+
5+
int main() {
6+
char password[100];
7+
int length = 0, upper=0, lower=0, digit=0, special=0;
8+
9+
printf("Enter your password: ");
10+
scanf("%s", password);
11+
12+
length = strlen(password);
13+
14+
for(int i=0; password[i] != '\0'; i++) {
15+
if(isupper(password[i])) upper = 1;
16+
else if(islower(password[i])) lower = 1;
17+
else if(isdigit(password[i])) digit = 1;
18+
else special = 1;
19+
}
20+
21+
int strength = upper + lower + digit + special + (length >= 8 ? 1 : 0);
22+
23+
printf("\nPassword Strength: ");
24+
if(strength <= 2) printf("Weak\n");
25+
else if(strength == 3 || strength == 4) printf("Medium\n");
26+
else printf("Strong\n");
27+
28+
return 0;
29+
}

0 commit comments

Comments
 (0)