-
Notifications
You must be signed in to change notification settings - Fork 0
/
task3.py
109 lines (73 loc) · 3.35 KB
/
task3.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
88
89
90
91
92
93
94
# task 3
# Password Generator Application
# import random and string for the random numbers & string
import random
import string
# Define the character sets for the password
lower = string.ascii_lowercase
upper = string.ascii_uppercase
numbers = string.digits
special_characters = '@!#&*_'
all_characters = lower + upper + numbers + special_characters
# Welcome dashboard
try:
print(" ┌─────────────────────────────────────────────────┐")
print(" │ WELCOME TO THE PASSWORD GENERATOR │")
print(" └─────────────────────────────────────────────────┘")
print('''
GUIDELINES:
- Choose the length of your password.
- The password can include uppercase letters, digits, and special characters.
- You can customize the complexity of your password.
Let's generate a password to enhance your security!!\n''')
# Ask the user for password complexity
print("What kind of password complexity are you comfortable with?\n- Strong\n- Moderate\n- Weak")
# loop if the user enter the invalid input
while True:
pass_strength = input('Enter your desired complexity: ').lower()
if pass_strength == 'strong':
print('For Strong Passwords: Password length should be greater than 8.')
break
elif pass_strength == 'moderate':
print('For Moderate Passwords: Password length range must be between (6-8).')
break
elif pass_strength == 'weak':
print('RISK!!\nWeak passwords are easy to hack...Choose carefully.')
print('For Weak Passwords: Password length should be less than 6.')
break
else:
print('Invalid Input!!')
# For the length of the password entered by the user
# loop for if length is not under the condition required by user
while True:
pass_length = int(input("Enter the desired password length: "))
if pass_strength == 'strong' and pass_length <= 8:
print('Length must be greater than 8')
continue
elif pass_strength == 'moderate' and not (6 <= pass_length <= 8):
print('Length range must be between (5-8)')
continue
elif pass_strength == 'weak' and pass_length >= 6:
print('Length must be less than 6')
continue
if pass_length <= 0:
print("Password length must be greater than zero.")
else:
password = ''
for pasw in range(pass_length):
password += random.choice(all_characters)
# Generate and display the password
print(f'Generated Password: {password}')
print('Congratulations! Your password has been created.')
# Check the strength and print the complexity and password
strength = "Weak"
if len(password) >= 9:
strength = "Strong"
elif len(password) >= 6:
strength = "Moderate"
print(f'Password Strength: {strength}')
print('Thanks for using!')
break
# exception handling
except ValueError:
print("Invalid input!! Please enter a valid number.")