-
Notifications
You must be signed in to change notification settings - Fork 0
/
PasswordGenRUN.py
229 lines (183 loc) · 9.6 KB
/
PasswordGenRUN.py
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5 import QtWidgets as qt
from PyQt5 import QtGui as gui
from PyQt5 import QtCore
from PasswordGenUI import Ui_Dialog as ui
import sys,re,string,random
class Window(qt.QMainWindow):
def __init__(self):
super(Window, self).__init__()
self.ui = ui()
self.ui.setupUi(self) # Initalize UI
self.oldPos = self.pos()
self.ui.btnGenerate.move(self.ui.btnGenerate.x()+80,self.ui.btnGenerate.y())
for group in qt.QMainWindow.parentWidget().findChildren(QWidget):
print(group)
# Connect ButtonPress event to functions
self.ui.btnGenerate.clicked.connect(self.passGen)
self.ui.btncopy.clicked.connect(self.copyToCLipboard)
self.ui.btnMin.clicked.connect(self.minimizeApp)
self.ui.btnMax.clicked.connect(self.maximizeApp)
self.ui.btnClose.clicked.connect(self.closeApp)
# MouseHover event for minimize,maximize,close buttons
self.ui.btnMin.installEventFilter(self)
self.ui.btnMax.installEventFilter(self)
self.ui.btnClose.installEventFilter(self)
self.ui.txtPass.setAlignment(QtCore.Qt.AlignCenter)
self.ui.txtPass.setDisabled(True) # Disable password field
self.setWindowFlag(QtCore.Qt.FramelessWindowHint) # Remove default titlebar
# Random Password Generating function
def passGen(self) :
global characters,Upper,Lower,Nums,Symbol
Upper,Lower,Nums,Symbol = False,False,False,False
if self.ui.checkUppercase.isChecked() and self.ui.checkLowercase.isChecked() and self.ui.checkNumbers.isChecked() and self.ui.checkSymbols.isChecked() :
Upper,Lower,Nums,Symbol = True,True,True,True
divi = 4
characters = list(string.ascii_lowercase + string.ascii_uppercase + string.digits + "!@#$%^&*()")
elif self.ui.checkUppercase.isChecked() and self.ui.checkLowercase.isChecked() and self.ui.checkNumbers.isChecked() :
Upper,Lower,Nums = True,True,True
divi = 3
characters = list(string.ascii_lowercase + string.ascii_uppercase + string.digits)
elif self.ui.checkUppercase.isChecked() and self.ui.checkLowercase.isChecked() and self.ui.checkSymbols.isChecked() :
Upper,Lower,Symbol = True,True,True
divi = 3
characters = list(string.ascii_lowercase + string.ascii_uppercase + "!@#$%^&*()")
elif self.ui.checkLowercase.isChecked() and self.ui.checkSymbols.isChecked() and self.ui.checkNumbers.isChecked() :
Lower,Nums,Symbol = True,True,True
divi = 3
characters = list(string.ascii_lowercase + string.digits + "!@#$%^&*()")
elif self.ui.checkUppercase.isChecked() and self.ui.checkSymbols.isChecked() and self.ui.checkNumbers.isChecked() :
Upper,Nums,Symbol = True,True,True
divi = 3
characters = list(string.ascii_uppercase + string.digits + "!@#$%^&*()")
elif self.ui.checkUppercase.isChecked() and self.ui.checkLowercase.isChecked() :
Upper,Lower = True,True
divi = 2
characters = list(string.ascii_lowercase + string.ascii_uppercase)
elif self.ui.checkSymbols.isChecked() and self.ui.checkNumbers.isChecked() :
Nums,Symbol = True,True
divi = 2
characters = list(string.digits + "!@#$%^&*()")
elif self.ui.checkSymbols.isChecked() and self.ui.checkLowercase.isChecked() :
Lower,Symbol = True,True
divi = 2
characters = list(string.ascii_lowercase + "!@#$%^&*()")
elif self.ui.checkUppercase.isChecked() and self.ui.checkNumbers.isChecked() :
Upper,Nums = True,True
divi = 2
characters = list(string.ascii_uppercase + string.digits)
elif self.ui.checkSymbols.isChecked() and self.ui.checkUppercase.isChecked() :
Upper,Symbol = True,True
divi = 2
characters = list(string.ascii_uppercase + "!@#$%^&*()")
elif self.ui.checkLowercase.isChecked() and self.ui.checkNumbers.isChecked() :
Lower,Nums = True,True
divi = 2
characters = list(string.ascii_lowercase + string.digits)
elif self.ui.checkUppercase.isChecked() :
Upper = True
divi = 1
characters = list(string.ascii_uppercase)
elif self.ui.checkLowercase.isChecked() :
Lower = True
divi = 1
characters = list(string.ascii_lowercase)
elif self.ui.checkNumbers.isChecked() :
Nums = True
divi = 1
characters = list(string.digits)
elif self.ui.checkSymbols.isChecked() :
Symbol = True
divi = 1
characters = list("!@#$%^&*()")
else :
msg1 = qt.QMessageBox()
msg1.setIcon(qt.QMessageBox.Warning)
msg1.setText("At least one checkbox must be selected !")
msg1.setWindowTitle("Checkbox Not Selected")
msg1.setStandardButtons(qt.QMessageBox.Ok)
msg1.exec_()
alphabet_lower = list(string.ascii_lowercase)
alphabet_upper = list(string.ascii_uppercase)
digits = list(string.digits)
special_characters = list("!@#$%^&*()")
length = self.ui.Pass_length.value()
password = []
characters_count = 0
if Lower == True :
lowercase_count = random.randint(1,length//divi)
for i in range(lowercase_count):
password.append(random.choice(alphabet_lower))
characters_count += lowercase_count
if Upper == True :
uppercase_count = random.randint(1,length//divi)
for i in range(uppercase_count):
password.append(random.choice(alphabet_upper))
characters_count += uppercase_count
if Nums == True :
digits_count = random.randint(1,length//divi)
for i in range(digits_count):
password.append(random.choice(digits))
characters_count += digits_count
if Symbol == True :
special_characters_count = random.randint(1,length//divi)
for i in range(special_characters_count):
password.append(random.choice(special_characters))
characters_count += special_characters_count
if characters_count < length:
random.shuffle(characters)
for i in range(length - characters_count):
password.append(random.choice(characters))
random.shuffle(password)
self.ui.txtPass.setText("".join(password))
# function for copy btton
def copyToCLipboard(self) :
import clipboard
copytext = self.ui.txtPass.text()
if len(copytext) > 0 :
clipboard.copy(copytext)
# minimize button functionality
def minimizeApp(self) :
self.showMinimized()
# maximize button functionality
def maximizeApp(self) :
if self.isMaximized() :
self.showNormal()
#self.ui.btnMax.setStyleSheet("background-image: url(C:/Users/Dimuth De Zoysa/Downloads/maximize4.png);background-color: transparent;")
else :
self.showMaximized()
#self.ui.btnMax.setStyleSheet("background-image: url(C:/Users/Dimuth De Zoysa/Downloads/restore.png);background-color: transparent;")
# close button functionality
def closeApp(self) :
self.close()
def mousePressEvent(self, event):
self.oldPos = event.globalPos()
def mouseMoveEvent(self, event):
delta = QPoint(event.globalPos() - self.oldPos)
self.move(self.x() + delta.x(), self.y() + delta.y())
self.oldPos = event.globalPos()
# MouseHover Event > change button images
def eventFilter(self, object, event):
if event.type() == QEvent.Enter and object is self.ui.btnMin :
self.ui.btnMin.setStyleSheet("background-image: url(/ICO/minimize_highlight.png);background-color: transparent;")
return True
elif event.type() == QEvent.Leave and object is self.ui.btnMin :
self.ui.btnMin.setStyleSheet("background-image: url(/ICO/minimize_normal.png);background-color: transparent;")
if event.type() == QEvent.Enter and object is self.ui.btnMax :
self.ui.btnMax.setStyleSheet("background-image: url(/ICO/maximize_highlight.png);background-color: transparent;")
return True
elif event.type() == QEvent.Leave and object is self.ui.btnMax :
self.ui.btnMax.setStyleSheet("background-image: url(ICO/maximize_normal.png);background-color: transparent;")
if event.type() == QEvent.Enter and object is self.ui.btnClose :
self.ui.btnClose.setStyleSheet("background-image: url(/ICO/close_highlight.png);background-color: transparent;")
return True
elif event.type() == QEvent.Leave and object is self.ui.btnClose :
self.ui.btnClose.setStyleSheet("background-image: url(/ICO/close_normal.png);background-color: transparent;")
return False
# Run Application
app = qt.QApplication([])
application = Window()
application.show()
app.exec()