-
Notifications
You must be signed in to change notification settings - Fork 0
/
function12.py
53 lines (37 loc) · 1.21 KB
/
function12.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
# Categorizing password as Strong or
# Weak in Python using Regex
import re
# Function to categorize password
def password(v):
# the password should not be a
# newline or space
if v == "\n" or v == " ":
return "Password cannot be a newline or space!"
# the password length should be in
# between 9 and 20
if 9 <= len(v) <= 20:
# checks for occurrence of a character
# three or more times in a row
if re.search(r'(.)\1\1', v):
return "Weak Password: Same character repeats three or more times in a row"
# checks for occurrence of same string
# pattern( minimum of two character length)
# repeating
if re.search(r'(..)(.*?)\1', v):
return "Weak password: Same string pattern repetition"
else:
return "Strong Password!"
else:
return "Password length must be 9-20 characters!"
# Main method
def main():
# Enter the email
while True:
passw = input(
'Enter the Password to check the strength or press X to exit: ')
if passw == 'X' or passw == 'x':
break
print(password(passw))
# Driver Code
if __name__ == '__main__':
main()