0% found this document useful (0 votes)
5 views

Import String

Uploaded by

4fxstrange
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Import String

Uploaded by

4fxstrange
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import tkinter as tk

import string
import random
import clipboard

def generate_password():
global previous_password

min_length = int(min_length_entry.get() or 8)
max_length = int(max_length_entry.get() or 16)
if min_length > max_length:
min_length, max_length = max_length, min_length

characters = string.ascii_letters + string.digits + '@#$%!&'


password_length = random.randint(min_length, max_length)
password = ''.join(random.choice(characters) for i in range(password_length))

if (any(c.islower() for c in password) and


any(c.isupper() for c in password) and
any(c.isdigit() for c in password) and
any(c in "@#$%!&" for c in password)):
previous_password = password
password_entry.delete(0, tk.END)
password_entry.insert(0, previous_password)
else:
show_warning_message()
generate_password()

def show_warning_message():
warning_label = tk.Label(root, text="The generated password doesn't meet
complexity requirements. Try increasing the length or adding more character sets.",
fg='red', font="bold")
warning_label.grid(row=5, column=0, columnspan=2, padx=10, pady=10)

def clear_password():
password_entry.delete(0, tk.END)

def copy_to_clipboard():
clipboard.copy(password_entry.get())

def change_bg_color():
color_chosen = color_var.get()
password_entry.config(bg=color_chosen)

root = tk.Tk()
root.title("Password Generator")

tk.Label(root, text="Default Length: 9", font="bold").grid(row=0, column=0)

min_length_label = tk.Label(root, text="Minimum length:", font=7)


min_length_label.grid(row=1, column=0, padx=10, pady=10)
min_length_entry = tk.Entry(root, width=10, borderwidth=2)
min_length_entry.grid(row=1, column=1, padx=10, pady=10)

max_length_label = tk.Label(root, text="Maximum length:", font=7)


max_length_label.grid(row=2, column=0, padx=10, pady=10)
max_length_entry = tk.Entry(root, width=10, borderwidth=2)
max_length_entry.grid(row=2, column=1, padx=10, pady=10)
generate_button = tk.Button(root, text="Generate Password", font=("Arial", 14),
bg='#2E86C1', fg='#FFFFFF', command=generate_password)
generate_button.grid(row=3, column=0, columnspan=2, padx=10, pady=10)

password_label = tk.Label(root, text="Generated Password:", font=7)


password_label.grid(row=5, column=0, padx=10, pady=10)

password_entry = tk.Entry(root, font=4, width=30, borderwidth=2)


password_entry.grid(row=5, column=1, padx=10, pady=10)

clipboard_button = tk.Button(root, text="Copy to clipboard", font=("Arial",


14 ,'italic'), bg='#2E86C1', fg='#FFFFFF', command=copy_to_clipboard)
clipboard_button.grid(row=4, column=0,columnspan=2 ,padx=10, pady=10)

previous_password=''
root.mainloop()

You might also like