-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpasswordGenerator.py
More file actions
58 lines (47 loc) · 1.61 KB
/
Copy pathpasswordGenerator.py
File metadata and controls
58 lines (47 loc) · 1.61 KB
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
import random
import string
def generate_strong_password(length=16):
lowercase = string.ascii_lowercase
uppercase = string.ascii_uppercase
digits = string.digits
special = string.punctuation
password = [
random.choice(lowercase),
random.choice(uppercase),
random.choice(digits),
random.choice(special)
]
all_chars = lowercase + uppercase + digits + special
password += random.choices(all_chars, k=length - 4)
random.shuffle(password)
return ''.join(password)
def main():
print("Strong Password Generator\n")
while True:
try:
length = input("Enter password length (minimum 8, recommended 16+): ")
length = int(length)
if length < 8:
print("Password too short! Minimum length is 8 characters.\n")
continue
break
except ValueError:
print("Please enter a valid number.\n")
password = generate_strong_password(length)
print(f"\nYour strong password: {password}")
print(f"Password length: {len(password)} characters")
print("\nPassword includes:")
print("✓ Lowercase letters")
print("✓ Uppercase letters")
print("✓ Numbers")
print("✓ Special characters")
while True:
again = input("\nGenerate another password? (y/n): ").lower()
if again == 'y':
password = generate_strong_password(length)
print(f"\nYour strong password: {password}")
else:
print("\nStay secure!")
break
if __name__ == "__main__":
main()