-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSp.py
More file actions
60 lines (50 loc) · 2.47 KB
/
Sp.py
File metadata and controls
60 lines (50 loc) · 2.47 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import re
# Function checks if the string contains any special character, upper, lower case, and length
def check_password_strength(string):
# Create regex patterns
regex_special = re.compile('[!@_!#$%^&*()<>?/\\|}{~:]')
regex_up = re.compile('[A-Z]')
regex_lc = re.compile('[a-z]')
regex_d = re.compile('[0-9]')
criteria = 0 # Counter for failed criteria
missing_criteria = [] # List to store the feedback messages for failed rules
# Check string length
if len(string) < 8:
criteria += 1
missing_criteria.append("Password should be at least 8 characters.")
# Check if uppercase letter is present
if not regex_up.search(string):
criteria += 1
missing_criteria.append("Uppercase letter is not present.")
# Check if lowercase letter is present
if not regex_lc.search(string):
criteria += 1
missing_criteria.append("Lowercase letter is not present.")
# Check if a digit is present
if not regex_d.search(string):
criteria += 1
missing_criteria.append("Digit is not present.")
# Check if special character is present
if not regex_special.search(string):
criteria += 1
missing_criteria.append("Special character is not present.")
# Determine the strength based on the number of missing criteria
if criteria == 0:
return (True, "Very Strong", "Password meets all criteria.")
elif criteria == 1:
return (False, "Strong", f"Password is strong. Missing the following criterion: {missing_criteria[0]}")
elif criteria == 2:
return (False, "Moderate", f"Password is moderate. Missing the following criteria: {', '.join(missing_criteria)}")
elif criteria == 3:
return (False, "Weak", f"Password is weak. Missing the following criteria: {', '.join(missing_criteria)}")
elif criteria == 4:
return (False, "Very Weak", f"Password is very weak. Missing the following criteria: {', '.join(missing_criteria)}")
else:
return (False, "Very Weak", f"Password is very weak. Missing all criteria: {', '.join(missing_criteria)}")
string = input("Please Enter Password\nIt should be more than 8 characters in length, should have at least one uppercase, lowercase, digit, and special character.\n")
result, strength, message = check_password_strength(string)
# Output password strength and message
if result:
print(message)
else:
print(f"{message} Your password is considered {strength}.")