forked from TheAlgorithms/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_strong_password.py
47 lines (34 loc) · 1.26 KB
/
check_strong_password.py
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
# This Will Check Whether A Given Password Is Strong Or Not
# It Follows The Rule that Length Of Password Should Be At Least 8 Characters
# And At Least 1 Lower, 1 Upper, 1 Number And 1 Special Character
import re
def strong_password_detector(password: str) -> str:
"""
>>> strong_password_detector('Hwea7$2!')
'This is a strong Password'
>>> strong_password_detector('Sh0r1')
'Your Password must be at least 8 characters long'
>>> strong_password_detector('Hello123')
'Password should contain UPPERCASE, lowercase, numbers, special characters'
"""
upper = re.compile(r"[A-Z]")
lower = re.compile(r"[a-z]")
num = re.compile(r"[0-9]")
spec_char = re.compile(r"[!@#$\^&\*\(\):;\'\"<>,\.\?\/|]")
if re.compile(r"\s").search(password) or len(password) < 8:
return "Your Password must be at least 8 characters long"
elif (
upper.search(password)
and lower.search(password)
and num.search(password)
and spec_char.search(password)
):
return "This is a strong Password"
else:
return (
"Password should contain UPPERCASE, lowercase, "
"numbers, special characters"
)
if __name__ == "__main__":
import doctest
doctest.testmod()