🔐 Simple Password Generator using Python (Console)
In this project, we create a simple password generator using Python. This program will create passwords using numbers, letters, symbols or all of them together. The user can choose the type and length of the password.
📌 What You Will Learn:
- How to use random choice in Python
- How to get user input
- How to build logic with classes and methods
🧑💻 Python Code:
from random import choice from colorama import Fore, Style, init init(autoreset=True) class Generate(): def __init__(self): self.upper = "ABCEDFGHIJKLMNOPQRSTUVWXYZ" self.lower = "abcedfghijklmnopqrstuvwxyz" self.number = "0987654321" self.symbols = "!@#$%^&*()" def number_pass(self, length: int) -> str: self.password = "" for _ in range(length): self.password += choice(self.number) return self.password def alpha_pass(self, length: int) -> str: self.password = "" self.all = self.upper + self.lower for _ in range(length): self.password += choice(self.all) return self.password def symbol_pass(self, length: int) -> str: self.password = "" for _ in range(length): self.password += choice(self.symbols) return self.password def all_pass(self, length: int) -> str: self.password = "" self.all = self.upper + self.lower + self.number + self.symbols for _ in range(length): self.password += choice(self.all) return self.password if __name__ == "__main__": passwords = Generate() try: print(Fore.YELLOW + "\n\t📌 MENU:") print(Fore.YELLOW + "1. Number Password") print("2. Alphabet Password") print("3. Symbol Password") print("4. Number + Alpha + Symbol Password") n = int(input(Fore.CYAN + "\nEnter a Choice (1–4): ")) lens = int(input(Fore.CYAN + "Enter Password Length: ")) if n == 1: print(Fore.GREEN + "✅ Your Password:", passwords.number_pass(lens)) elif n == 2: print(Fore.GREEN + "✅ Your Password:", passwords.alpha_pass(lens)) elif n == 3: print(Fore.GREEN + "✅ Your Password:", passwords.symbol_pass(lens)) elif n == 4: print(Fore.GREEN + "✅ Your Password:", passwords.all_pass(lens)) else: print(Fore.RED + "❌ Invalid Choice. Please enter between 1 and 4.") except ValueError: print(Fore.RED + "❌ Invalid Input. Please enter a number only.")
✅ Example:
If you choose option 4 and length 8, you may get a password like: A3@u7#Tq This password includes numbers, symbols, uppercase and lowercase letters.
💬 Final Words:
This is a good project for anyone learning Python. It uses class, input, loops, and random logic. You can even make a GUI version later.
👉 Follow our blog and YouTube channel for more simple Python projects!