|
| 1 | +import random |
| 2 | +import tkinter as tk |
| 3 | +from tkinter import messagebox |
| 4 | + |
| 5 | +def passwordGenerator(): |
| 6 | + if(entry1.get() == "" or entry2.get() == "" or entry3.get() == "" or entry4.get() == "" or entry5.get() == ""): |
| 7 | + messagebox.showerror("Error", "Please fill all the fields.") |
| 8 | + return |
| 9 | + elif((entry2.get() != 'y' and entry2.get() != 'Y' and entry2.get() != 'n' and entry2.get() != 'N') or (entry3.get() != 'y' and entry3.get() != 'Y' and entry3.get() != 'n' and entry3.get() != 'N') or (entry4.get() != 'y' and entry4.get() != 'Y' and entry4.get() != 'n' and entry4.get() != 'N') or (entry5.get() != 'y' and entry5.get() != 'Y' and entry5.get() != 'n' and entry5.get() != 'N')): |
| 10 | + messagebox.showerror("Error", "Please enter 'y' or 'n' for yes or no questions respectively.") |
| 11 | + return |
| 12 | + |
| 13 | + length = int(entry1.get()) |
| 14 | + ch = entry2.get() |
| 15 | + lowerAlphabets = entry3.get() |
| 16 | + upperAlphabets = entry4.get() |
| 17 | + numbers = entry5.get() |
| 18 | + password = "" |
| 19 | + |
| 20 | + if ch == 'y' or ch == 'Y': |
| 21 | + password += "!@#$%^&*()_+" |
| 22 | + if lowerAlphabets == 'y' or lowerAlphabets == 'Y': |
| 23 | + password += "abcdefghijklmnopqrstuvwxyz" |
| 24 | + if upperAlphabets == 'y' or upperAlphabets == 'Y': |
| 25 | + password += "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 26 | + if numbers == 'y' or numbers == 'Y': |
| 27 | + password += "0123456789" |
| 28 | + |
| 29 | + passwordGenerated = "" |
| 30 | + for i in range(length): |
| 31 | + passwordGenerated += random.choice(password) |
| 32 | + messagebox.showinfo("Password Generator", "Your password is: " + passwordGenerated) |
| 33 | + |
| 34 | +window = tk.Tk() |
| 35 | +window.title("Password Generator") |
| 36 | +window.geometry("600x400") |
| 37 | +window.resizable(False, False) |
| 38 | + |
| 39 | +label1 = tk.Label(window, text="Password Generator", font=("Arial", 20)) |
| 40 | +label1.pack() |
| 41 | + |
| 42 | +label2 = tk.Label(window, text="------------------", font=("Arial", 20)) |
| 43 | +label2.pack() |
| 44 | + |
| 45 | +label3 = tk.Label(window, text="For yes or no questions, enter 'y' or 'n' respectively. (Case insensitive)", font=("Arial", 10)) |
| 46 | +label3.pack() |
| 47 | + |
| 48 | +label4 = tk.Label(window, text="Enter the length of password: ", font=("Arial", 10)) |
| 49 | +label4.pack() |
| 50 | + |
| 51 | +entry1 = tk.Entry(window, width=10) |
| 52 | +entry1.pack() |
| 53 | + |
| 54 | +label5 = tk.Label(window, text="Do you want to include special characters? (y/n): ", font=("Arial", 10)) |
| 55 | +label5.pack() |
| 56 | + |
| 57 | +entry2 = tk.Entry(window, width=10) |
| 58 | +entry2.pack() |
| 59 | + |
| 60 | +label6 = tk.Label(window, text="Do you want to include lower case alphabets? (y/n): ", font=("Arial", 10)) |
| 61 | +label6.pack() |
| 62 | + |
| 63 | +entry3 = tk.Entry(window, width=10) |
| 64 | +entry3.pack() |
| 65 | + |
| 66 | +label7 = tk.Label(window, text="Do you want to include upper case alphabets? (y/n): ", font=("Arial", 10)) |
| 67 | +label7.pack() |
| 68 | + |
| 69 | +entry4 = tk.Entry(window, width=10) |
| 70 | +entry4.pack() |
| 71 | + |
| 72 | +label8 = tk.Label(window, text="Do you want to include numbers? (y/n): ", font=("Arial", 10)) |
| 73 | +label8.pack() |
| 74 | + |
| 75 | +entry5 = tk.Entry(window, width=10) |
| 76 | +entry5.pack() |
| 77 | + |
| 78 | +button1 = tk.Button(window, text="Generate Password", command=passwordGenerator) |
| 79 | +button1.pack() |
| 80 | + |
| 81 | +window.mainloop() |
0 commit comments