This project is a Graphical User Interface (GUI) based password generator created using
Python and Tkinter. It allows users to generate strong passwords with customizable options
and additional security features.
🔹 Features of the Project:
1. Custom Password Length – Users can enter a desired length (default: 12
characters).
2. Character Type Selection – Users can choose to include:
o ✅ Uppercase Letters (A-Z)
o ✅ Lowercase Letters (a-z)
o ✅ Digits (0-9)
o ✅ Symbols (!@#$%^&* etc.)
3. Avoid Ambiguous Characters – Prevents confusing characters like O, 0, l, 1, I, |.
4. Ensures at Least One of Each Selected Type – Increases password strength.
5. Password Strength Checker – Rates password strength from 0 to 10 based on
complexity.
6. Copy to Clipboard – Quickly copy the generated password.
7. Save Password to File – Saves the generated password in passwords.txt for later
use.
8. Generate QR Code for Password – The password can be saved as a QR code to
scan later.
9. Simple and User-Friendly GUI – Built using Tkinter for ease of use.
Page 1 of 15
🔹 Libraries Used in the Password Generator Project
1. tkinter – Used to create the Graphical User Interface (GUI).
o Provides buttons, labels, checkboxes, entry fields, and other UI elements.
2. random – Used to randomly select characters when generating passwords.
o Ensures strong and unpredictable passwords.
3. string – Provides pre-defined character sets like:
o string.ascii_uppercase → A-Z
o string.ascii_lowercase → a-z
o string.digits → 0-9
o string.punctuation → Special symbols
4. pyperclip – Allows copying the generated password to the clipboard.
o Enables quick and easy pasting without typing.
5. qrcode – Generates a QR code for the password.
o Users can scan the QR code to retrieve the password securely.
6. PIL (Pillow) – Used to display the QR code image in the GUI.
o Image.open() loads images.
o ImageTk.PhotoImage() integrates images with Tkinter.
7. messagebox (from tkinter) – Displays popup messages.
o Used for alerts like "Password copied!" or "Password saved!"
Page 2 of 15
🔹 How the Code Works:
GUI Setup (Tkinter)
tk.Tk() creates the main application window.
The window title, size, and layout are set.
Tkinter StringVar and BooleanVar variables store user inputs.
CODE:
root = tk.Tk()
root.title("🔐 Password Generator")
root.geometry("400x500")
root.resizable(False, False)
# Variables
length_var = tk.StringVar(value="12")
upper_var = tk.BooleanVar(value=True)
lower_var = tk.BooleanVar(value=True)
digits_var = tk.BooleanVar(value=True)
symbols_var = tk.BooleanVar(value=True)
ambiguous_var = tk.BooleanVar(value=False)
Page 3 of 15
Password Generation Logic
Collects user preferences (upper_var, lower_var, etc.).
Builds a character pool from the selected options.
Ensures at least one of each selected type.
Randomly shuffles the characters to generate a secure password.
CODE:
def generate_password():
length = int(length_var.get())
use_upper = upper_var.get()
use_lower = lower_var.get()
use_digits = digits_var.get()
use_symbols = symbols_var.get()
avoid_ambiguous = ambiguous_var.get()
upper_chars = string.ascii_uppercase
lower_chars = string.ascii_lowercase
digit_chars = string.digits
symbol_chars = string.punctuation
ambiguous_chars = "O0l1I|"
if avoid_ambiguous:
upper_chars = "".join(c for c in upper_chars if c not in ambiguous_chars)
lower_chars = "".join(c for c in lower_chars if c not in ambiguous_chars)
digit_chars = "".join(c for c in digit_chars if c not in ambiguous_chars)
symbol_chars = "".join(c for c in symbol_chars if c not in ambiguous_chars)
char_set = ""
if use_upper: char_set += upper_chars
if use_lower: char_set += lower_chars
if use_digits: char_set += digit_chars
if use_symbols: char_set += symbol_chars
if not char_set:
messagebox.showerror("Error", "Please select at least one character type!")
return
Page 4 of 15
password = []
if use_upper: password.append(random.choice(upper_chars))
if use_lower: password.append(random.choice(lower_chars))
if use_digits: password.append(random.choice(digit_chars))
if use_symbols: password.append(random.choice(symbol_chars))
password.extend(random.choice(char_set) for _ in range(length - len(password)))
random.shuffle(password)
password_str = "".join(password)
password_entry.delete(0, tk.END)
password_entry.insert(0, password_str)
check_password_strength(password_str)
Password Strength Checker
Checks the number of uppercase, lowercase, digits, and symbols.
Uses a scoring system to rate password strength from 0 to 10.
CODE:
def check_password_strength(password):
strength = sum([
any(c in string.ascii_uppercase for c in password),
any(c in string.ascii_lowercase for c in password),
any(c in string.digits for c in password),
any(c in string.punctuation for c in password),
]) * 2.5 + min(len(password) / 2, 10)
strength_label.config(text=f"Strength: {min(strength, 10):.1f}/10")
Page 5 of 15
Copy to Clipboard
Uses the pyperclip module to copy the password.
CODE:
def copy_to_clipboard():
pyperclip.copy(password_entry.get())
messagebox.showinfo("Copied", "Password copied to clipboard!")
Save Password to File
Saves the password in passwords.txt.
CODE:
def save_password():
password = password_entry.get()
if password:
with open("passwords.txt", "a") as file:
file.write(password + "\n")
messagebox.showinfo("Saved", "Password saved to passwords.txt!")
Generate QR Code
Converts the password into a QR code using the qrcode module.
Saves the QR code as an image file.
CODE:
def generate_qr():
password = password_entry.get()
if password:
qr = qrcode.make(password)
qr.save("password_qr.png")
img = Image.open("password_qr.png")
img = img.resize((150, 150))
img = ImageTk.PhotoImage(img)
qr_label.config(image=img)
qr_label.image = img
messagebox.showinfo("QR Code", "QR Code saved as 'password_qr.png'.")
Page 6 of 15
User Interface (UI)
The Tkinter UI elements (buttons, labels, checkboxes, entry fields) are set up.
CODE:
tk.Label(root, text="Password Length:").pack(pady=5)
tk.Entry(root, textvariable=length_var, width=5).pack()
tk.Checkbutton(root, text="Include Uppercase (A-Z)", variable=upper_var).pack()
tk.Checkbutton(root, text="Include Lowercase (a-z)", variable=lower_var).pack()
tk.Checkbutton(root, text="Include Digits (0-9)", variable=digits_var).pack()
tk.Checkbutton(root, text="Include Symbols (@#$!)", variable=symbols_var).pack()
tk.Checkbutton(root, text="Avoid Ambiguous Characters", variable=ambiguous_var).pack()
tk.Button(root, text="Generate Password", command=generate_password).pack(pady=10)
password_entry = tk.Entry(root, width=30, font=("Arial", 14), justify="center")
password_entry.pack(pady=5)
strength_label = tk.Label(root, text="Strength: --/10", fg="blue")
strength_label.pack()
tk.Button(root, text="Copy to Clipboard", command=copy_to_clipboard).pack(pady=5)
tk.Button(root, text="Save to File", command=save_password).pack(pady=5)
tk.Button(root, text="Generate QR Code", command=generate_qr).pack(pady=5)
qr_label = tk.Label(root)
qr_label.pack()
🔹 Conclusion
This GUI-based Password Generator is a beginner-friendly project that: ✅ Uses
Tkinter for a user-friendly interface.
Ensures secure password generation.
Provides advanced features like strength checking and QR codes
Page 7 of 15
Outputs:
Page 8 of 15
Page 9 of 15
Page 10 of 15
Page 11 of 15
Page 12 of 15
Page 13 of 15
Page 14 of 15
Page 15 of 15