π Python Password Generator (Console Version)
The following code script will generate strong and secure passwords. It will have Features like:
- π Prompts for custom password length (minimum 8)
- π‘ Includes lowercase, uppercase, digits, and symbols
- ✅ Ensures at least one of each character type
- π Shuffles characters for randomness
import random
import string
print("π Welcome to the Password Generator!")
# Ask for password length
while True:
try:
length = int(input("π Enter desired password length (8 or more): "))
if length < 8:
print("⚠️ Password should be at least 8 characters long.")
else:
break
except ValueError:
print("❌ Please enter a valid number.")
# Define character sets
letters = string.ascii_letters
digits = string.digits
symbols = "!@#$%^&*()_+-=[]{}|;:,.<>?/"
# Combine all characters
all_chars = letters + digits + symbols
# Ensure password contains at least one of each type
password = [
random.choice(string.ascii_lowercase),
random.choice(string.ascii_uppercase),
random.choice(digits),
random.choice(symbols)
]
# Fill the rest randomly
while len(password) < length:
password.append(random.choice(all_chars))
# Shuffle to avoid predictable pattern
random.shuffle(password)
# Convert list to string
final_password = ''.join(password)
print(f"✅ Your generated password is: {final_password}")