-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguiPasswordApp.py
More file actions
147 lines (117 loc) · 5.26 KB
/
Copy pathguiPasswordApp.py
File metadata and controls
147 lines (117 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from tkinter import *
from PIL import Image, ImageTk # Import Image
import random as rn
wordOptions = ['hello', 'hey', 'no', 'bye', 'hello',
'nope', 'horse', 'purple', 'hat', 'run',
'bay', 'lifting', 'austin', 'detroit',
'DND', 'diva', 'playstation', 'xbox',
'mom', 'trend', 'artifical', 'shell',
'venus', 'grimace', 'salvation', 'print',
'silver', 'bullet', 'fix', 'guerrilla',
'brick', 'ratio', 'overwhelm', 'eject']
wordInt = rn.randint(0,len(wordOptions) - 1)
letterOptions = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z']
letterInt = rn.randint(0, len(letterOptions) - 1)
numberOptions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18,
19, 20]
numberInt = rn.randint(0, len(numberOptions) - 1)
specialOptions = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')',
'|', '\\', '-', '_', '+', '=', ']', '}', '{', '[',
'"', "'", ':', ';']
specialInt = rn.randint(0, len(specialOptions) - 1)
# Create the main window
root = Tk()
root.title("Password Generator")
# Set the window size
rootGeometry = root.geometry("500x300")
# Configure background color
root.config(bg='blue')
# Create buttons/labels
welcome_label = Label(
root,
text = "Welcome to your password generator",
bg = 'blue',
fg = 'white'
)
welcome_label.pack(pady=10)
# Add resized image to GUI
try:
original_image = Image.open('/Users/diego/Desktop/Projects/PasswordGenerator/keyAndLock.png') # no image will appear, you have to put its file path.
resized_image = original_image.resize((100, 100), Image.Resampling.LANCZOS) # Resize to 100x100 pixels
image = ImageTk.PhotoImage(resized_image) # Convert to PhotoImage
image_label = Label(root, image=image)
image_label.pack(pady=10)
except Exception as e:
print(f"Error: {e}")
# Add sliders for user to choose how many letters, words, and special characters
# try:
# scaleWord = Scale(root, from_ = 0, to = len(wordOptions), orient=HORIZONTAL, label = "Words")
# wordValue = scaleWord.get()
# scaleWord.pack(pady = 5)
# scaleLetter = Scale(root, from_ = 0, to = len(letterOptions), orient=HORIZONTAL, label = "Letters")
# letterValue = scaleLetter.get()
# scaleLetter.pack(pady = 5)
# scaleSpecial = Scale(root, from_ = 0, to = len(specialOptions), orient=HORIZONTAL, label = "Special Characters")
# specialValue = scaleSpecial.get()
# scaleSpecial.pack(pady = 5)
# except NameError:
# print("Error: Ensure wordOptions, letterOptions, and specialOptions are defined in passwordGenerator.")
def generatePassword():
#create an empty list which is able to gain all words, letters, and specials characters. Capitalize randomizer as well.
wordList = []
letterList = []
specialList = []
numberList = []
for i in range(wordInt):
capitalizeWord = rn.randint(0,1)
if capitalizeWord == 1:
getWordLength = len(wordOptions[i])
if getWordLength % 2 == 0:
word = wordOptions[i].upper()
wordList.append(word)
else:
word = wordOptions[i]
wordList.append(word)
for j in range(letterInt):
capitalizeLetter = rn.randint(0,1)
if capitalizeLetter == 1:
letter = letterOptions[j].upper()
letterList.append(letter)
else:
letter = letterOptions[j]
letterList.append(letter)
for h in range(specialInt):
specialChar = specialOptions[h]
specialList.append(specialChar)
for k in range(numberInt):
number = str(numberOptions[k])
numberList.append(number)
#merge all lists, shuffles them, and then merges all the shuffles so that you don't have any \n
mergedLists = wordList + letterList + specialList + numberList
rn.shuffle(mergedLists)
password = ''.join(mergedLists)
#creating a new window to generate once you generate password, using the same dimensions as rootGeometry
passwordWindow = Toplevel(root)
passwordWindow.title("Generated Password is here!")
passwordWindow.geometry = rootGeometry
#puts text on the new window, passwordLabel is taking info from the password we created and displaying it
Label(passwordWindow, text = "Generated Password:", font = ("Arial", 14)).pack(pady = 10)
passwordLabel = Label(passwordWindow, text = password, font = ("Arial", 12), wraplength = 350, justify = "center")
passwordLabel.pack(pady = 10)
#function allows us to copy the password on display
def copyToClipboard():
root.clipboard_clear()
root.clipboard_append(password)
root.update()
#creating the button to copy
Button(passwordWindow, text = "Copy Password", command = copyToClipboard, font = ("Arial", 12)).pack(pady = 5)
generate_button = Button(root, text = "Generate Password", command = generatePassword, font = ('Arial', 12))
generate_button.pack(pady = 5)
#Adding the main function buttons
quitButton = Button(root, text = "Quit", command = root.destroy)
quitButton.pack(pady = 5)
# Run the application
root.mainloop()