-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathstrong_pw_detector.py
More file actions
executable file
·43 lines (35 loc) · 1.56 KB
/
strong_pw_detector.py
File metadata and controls
executable file
·43 lines (35 loc) · 1.56 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
#! /usr/bin/env python3
# strong_pw_detector.py - determines whether or not passed password is strong
import re
import sys
def check_pw_strength(password):
"""
Determines if the argument satisfies the requirements of a strong
password (uppercase, lowercase, digit, special character, and length >= 8)
:param str password: password to evaluate
:return: bool indicating whether or not the password is strong
"""
pw_regex = re.compile(r'''
^(?=.*?[A-Z]) # at least 1 capital letter
(?=.*?[a-z]) # at least 1 lower case letter
(?=.*?[0-9]) # at least 1 digit
(?=.*?[#?!@$%^&*()\-_=+./\\]) # at least 1 special character
.{8,}$ # at least 8 characters long
''', re.VERBOSE)
if pw_regex.search(password):
return True
return False
if __name__ == "__main__":
if len(sys.argv) < 2:
print('Usage: python strong_pw_detector.py [password] - determines if password is strong')
exit()
if check_pw_strength(password=str(sys.argv[1])):
print('The tested password is strong!')
else:
print('The tested password is not strong!'
'\nA strong password satisfies all of the following requirements:'
'\n\tcontains at least one lowercase character'
'\n\tcontains at least one uppercase character'
'\n\tcontains at least one digit'
'\n\tcontains at least one special character'
'\n\tis at least 8 digits in length')