This repository has been archived by the owner on Oct 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 756
/
PasswordStrengthChecker.py
87 lines (75 loc) · 2.41 KB
/
PasswordStrengthChecker.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
'''
password streingth checker
'''
import string
import getpass
def check_password_strength():
password = getpass.getpass('Enter the password: ')
strength = 0
remarks = ''
lower_count = upper_count = num_count = wspace_count = special_count = 0
for char in list(password):
if char in string.ascii_lowercase:
lower_count += 1
elif char in string.ascii_uppercase:
upper_count += 1
elif char in string.digits:
num_count += 1
elif char == ' ':
wspace_count += 1
else:
special_count += 1
if lower_count >= 1:
strength += 1
if upper_count >= 1:
strength += 1
if num_count >= 1:
strength += 1
if wspace_count >= 1:
strength += 1
if special_count >= 1:
strength += 1
if strength == 1:
remarks = ('That\'s a very bad password.'
' Change it as soon as possible.')
elif strength == 2:
remarks = ('That\'s a weak password.'
' You should consider using a tougher password.')
elif strength == 3:
remarks = 'Your password is okay, but it can be improved.'
elif strength == 4:
remarks = ('Your password is hard to guess.'
' But you could make it even more secure.')
elif strength == 5:
remarks = ('Now that\'s one hell of a strong password!!!'
' Hackers don\'t have a chance guessing that password!')
print('Your password has:-')
print(f'{lower_count} lowercase letters')
print(f'{upper_count} uppercase letters')
print(f'{num_count} digits')
print(f'{wspace_count} whitespaces')
print(f'{special_count} special characters')
print(f'Password Score: {strength / 5}')
print(f'Remarks: {remarks}')
def check_pwd(another_pw=False):
valid = False
if another_pw:
choice = input(
'Do you want to check another password\'s strength (y/n) : ')
else:
choice = input(
'Do you want to check your password\'s strength (y/n) : ')
while not valid:
if choice.lower() == 'y':
return True
elif choice.lower() == 'n':
print('Exiting...')
return False
else:
print('Invalid input...please try again. \n')
if __name__ == '__main__':
print('===== Welcome to Password Strength Checker =====')
check_pw = check_pwd()
while check_pw:
check_password_strength()
check_pw = check_pwd(True)