-
Notifications
You must be signed in to change notification settings - Fork 0
/
password.py
66 lines (52 loc) · 1.65 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import getpass
import re
isPassword = False
capitalLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def checkNumber(text):
if re.search(r"\d", text):
return True
else:
return False
def checkCapitalLetters(text):
if re.search(r"[A-Z]",text):
return True
else:
return False
def checkSpecialCharacters(text):
if re.search(r"\W", text):
return True
else:
return False
def checkPassword(password):
isCorrectPassword = (len(password) >= 8)
isCorrectPassword &= checkCapitalLetters(password)
isCorrectPassword &= checkNumber(password)
isCorrectPassword &= checkSpecialCharacters(password)
return isCorrectPassword
def newPassword():
global isPassword
if isPassword:
print("A password already exists")
else:
print('''
Choose a main password
At least :
- 8 characters
- 1 capital letter
- 1 number
- 1 special character
''')
# Input && Check password once and twice
print("Enter your main password.")
while True:
password = getpass.getpass(prompt='Password :', stream=None)
# Check once
if checkPassword(password):
secondPassword = getpass.getpass(prompt='Enter your password a second time :', stream=None)
# Check Twice
if secondPassword == password:
break
print("Incorrect : Your second password is not the same as the first one.")
continue
print("It's an invalid password.")
return password