-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpassword_project.py
executable file
·61 lines (35 loc) · 1.17 KB
/
password_project.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
48
49
50
51
52
53
54
55
#!/usr/bin/python
## Strong Password Detection Project
import re
def strongPassword(password):
## Define a strong password as one that:
## -has at least 8 characters
## -contains at least one uppercase character
## -contains at least one lowercase character
## -contains at least one digit
## Return True if password meets requirements.
## Otherwise, return False.
## Check that there are at least 8 characters:
check_1 = re.compile(r'[a-zA-Z0-9]{8,}')
if(check_1.search(password) == None):
return False
## Check that there is at least one uppercase character:
check_2 = re.compile(r'[A-Z]+')
if(check_2.search(password) == None):
return False
## Check that there is at least one lowercase character:
check_3 = re.compile(r'[a-z]+')
if(check_3.search(password) == None):
return False
## Check that there is at least one digit character:
check_4 = re.compile(r'[0-9]+')
if(check_4.search(password) == None):
return False
return True
## Test the function:
## ok:
print(strongPassword('Password123'))
## not ok:
print(strongPassword('Pa123'))
print(strongPassword('assword123'))
print(strongPassword('Password'))