forked from dimpeshmalviya/C-Language-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassword_Strength_Checker.c
More file actions
42 lines (35 loc) · 1.33 KB
/
Password_Strength_Checker.c
File metadata and controls
42 lines (35 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
char password[100];
int i, length, hasUpper = 0, hasLower = 0, hasDigit = 0, hasSpecial = 0;
printf("Enter your password: ");
fgets(password, sizeof(password), stdin);
password[strcspn(password, "\n")] = '\0'; // remove newline
length = strlen(password);
for (i = 0; i < length; i++) {
if (isupper(password[i]))
hasUpper = 1;
else if (islower(password[i]))
hasLower = 1;
else if (isdigit(password[i]))
hasDigit = 1;
else if (ispunct(password[i]))
hasSpecial = 1;
}
printf("\nPassword Analysis:\n");
printf("-------------------\n");
printf("Length: %d\n", length);
printf("Contains Uppercase: %s\n", hasUpper ? "Yes" : "No");
printf("Contains Lowercase: %s\n", hasLower ? "Yes" : "No");
printf("Contains Digit: %s\n", hasDigit ? "Yes" : "No");
printf("Contains Special Character: %s\n", hasSpecial ? "Yes" : "No");
if (length >= 8 && hasUpper && hasLower && hasDigit && hasSpecial)
printf("\n✅ Password Strength: STRONG\n");
else if (length >= 6 && ((hasUpper && hasLower) || hasDigit))
printf("\n⚠️ Password Strength: MODERATE\n");
else
printf("\n❌ Password Strength: WEAK\n");
return 0;
}