deezwend
Hectopat
- Katılım
- 28 Haziran 2021
- Mesajlar
- 294
- Çözümler
- 4
Daha fazla
- Cinsiyet
- Erkek
Merhaba, dünden beri bir password generator yazıyorum Python'da ve bugün çok şükür bitirebildim. Programın bir arayüzü var ve programa istemediğiniz veya istediğiniz karakterleri söylüyorsunuz, program da ona göre bir şifre oluşturuyor. İsterseniz şifreyi oluşturduktan sonra panoya kopyalamasını söyleyebilirsiniz ve şifreyi oluşturduktan sonra programa söylediğiniz konuma şifreyi ".txt" dosyasının içerisinde göndermesini söyleyebilirsiniz. En ince ayrıntısına kadar arayüzü yapmaya çalıştım. Nasıl olduğuna dair fikirlerinizi benimle paylaşırsanız sevinirim. Eleştirilere açığım. Eğer benim fark etmediğim bir hataya rastlarsanız burada belirtirseniz sevinirim. İyi akşamlar.
Bu arada "messagebox" ve "clipboard" kütüphanelerini indirmelisiniz.
Kodlar:
Bu arada "messagebox" ve "clipboard" kütüphanelerini indirmelisiniz.
Kodlar:
Python:
from clipboard import copy
import random
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from os.path import exists
import sys
from messagebox import askyesno, showinfo, showerror
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(794, 357)
Form.setMinimumSize(QtCore.QSize(794, 357))
Form.setMaximumSize(QtCore.QSize(794, 357))
Form.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("../../../Downloads/lock.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
Form.setWindowIcon(icon)
Form.setLayoutDirection(QtCore.Qt.LeftToRight)
Form.setStyleSheet("")
self.Options = QtWidgets.QGroupBox(Form)
self.Options.setGeometry(QtCore.QRect(10, 10, 361, 331))
font = QtGui.QFont()
font.setPointSize(12)
self.Options.setFont(font)
self.Options.setObjectName("Options")
self.include_numbers = QtWidgets.QCheckBox(self.Options)
self.include_numbers.setGeometry(QtCore.QRect(30, 30, 231, 17))
font = QtGui.QFont()
font.setPointSize(10)
self.include_numbers.setFont(font)
self.include_numbers.setObjectName("include_numbers")
self.special_characters = QtWidgets.QCheckBox(self.Options)
self.special_characters.setGeometry(QtCore.QRect(30, 50, 231, 17))
font = QtGui.QFont()
font.setPointSize(10)
self.special_characters.setFont(font)
self.special_characters.setObjectName("special_characters")
self.pass_length = QtWidgets.QCheckBox(self.Options)
self.pass_length.setGeometry(QtCore.QRect(30, 110, 231, 17))
font = QtGui.QFont()
font.setPointSize(10)
self.pass_length.setFont(font)
self.pass_length.setObjectName("pass_length")
self.uppercase = QtWidgets.QCheckBox(self.Options)
self.uppercase.setGeometry(QtCore.QRect(30, 70, 231, 17))
font = QtGui.QFont()
font.setPointSize(10)
self.uppercase.setFont(font)
self.uppercase.setObjectName("uppercase")
self.lower_case = QtWidgets.QCheckBox(self.Options)
self.lower_case.setGeometry(QtCore.QRect(30, 90, 231, 17))
font = QtGui.QFont()
font.setPointSize(10)
self.lower_case.setFont(font)
self.lower_case.setObjectName("lower_case")
self.length_combobox = QtWidgets.QComboBox(self.Options)
self.length_combobox.setGeometry(QtCore.QRect(30, 140, 191, 22))
self.length_combobox.setObjectName("length_combobox")
self.length_combobox.addItem("")
self.length_combobox.addItem("")
self.length_combobox.addItem("")
self.length_combobox.addItem("")
self.length_combobox.addItem("")
self.length_combobox.addItem("")
self.length_combobox.addItem("")
self.length_combobox.addItem("")
self.length_combobox.addItem("")
self.length_combobox.addItem("")
self.length_combobox.addItem("")
self.length_combobox.addItem("")
self.length_combobox.addItem("")
self.length_combobox.addItem("")
self.length_combobox.addItem("")
self.length_combobox.addItem("")
self.length_combobox.addItem("")
self.length_combobox.addItem("")
self.length_combobox.addItem("")
self.length_combobox.addItem("")
self.length_box = QtWidgets.QLineEdit(self.Options)
self.length_box.setGeometry(QtCore.QRect(30, 140, 191, 21))
self.length_box.setObjectName("length_box")
self.by_writing = QtWidgets.QCheckBox(self.Options)
self.by_writing.setGeometry(QtCore.QRect(30, 170, 291, 20))
font = QtGui.QFont()
font.setPointSize(10)
self.by_writing.setFont(font)
self.by_writing.setObjectName("by_writing")
self.copy_the_password = QtWidgets.QCheckBox(self.Options)
self.copy_the_password.setGeometry(QtCore.QRect(30, 200, 281, 17))
font = QtGui.QFont()
font.setPointSize(10)
self.copy_the_password.setFont(font)
self.copy_the_password.setObjectName("copy_the_password")
self.label = QtWidgets.QLabel(self.Options)
self.label.setGeometry(QtCore.QRect(220, 30, 131, 20))
font = QtGui.QFont()
font.setPointSize(10)
self.label.setFont(font)
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.Options)
self.label_2.setGeometry(QtCore.QRect(230, 50, 131, 20))
font = QtGui.QFont()
font.setPointSize(10)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.Options)
self.label_3.setGeometry(QtCore.QRect(230, 70, 131, 20))
font = QtGui.QFont()
font.setPointSize(10)
self.label_3.setFont(font)
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(self.Options)
self.label_4.setGeometry(QtCore.QRect(230, 90, 131, 20))
font = QtGui.QFont()
font.setPointSize(10)
self.label_4.setFont(font)
self.label_4.setObjectName("label_4")
self.location = QtWidgets.QLineEdit(self.Options)
self.location.setGeometry(QtCore.QRect(30, 260, 311, 20))
self.location.setObjectName("location")
self.save_the_password = QtWidgets.QCheckBox(self.Options)
self.save_the_password.setGeometry(QtCore.QRect(30, 230, 321, 17))
font = QtGui.QFont()
font.setPointSize(10)
self.save_the_password.setFont(font)
self.save_the_password.setObjectName("save_the_password")
self.send_the_location = QtWidgets.QPushButton(self.Options)
self.send_the_location.setGeometry(QtCore.QRect(180, 290, 161, 31))
font = QtGui.QFont()
font.setPointSize(14)
self.send_the_location.setFont(font)
self.send_the_location.setObjectName("send_the_location")
self.creating_the_password = QtWidgets.QGroupBox(Form)
self.creating_the_password.setGeometry(QtCore.QRect(380, 10, 401, 331))
font = QtGui.QFont()
font.setPointSize(12)
self.creating_the_password.setFont(font)
self.creating_the_password.setObjectName("creating_the_password")
self.label_5 = QtWidgets.QLabel(self.creating_the_password)
self.label_5.setGeometry(QtCore.QRect(20, 30, 111, 31))
font = QtGui.QFont()
font.setPointSize(14)
self.label_5.setFont(font)
self.label_5.setObjectName("label_5")
self.including_1_number = QtWidgets.QLabel(self.creating_the_password)
self.including_1_number.setGeometry(QtCore.QRect(20, 60, 331, 20))
font = QtGui.QFont()
font.setPointSize(10)
self.including_1_number.setFont(font)
self.including_1_number.setText("")
self.including_1_number.setObjectName("including_1_number")
self.including_2_special_characters = QtWidgets.QLabel(self.creating_the_password)
self.including_2_special_characters.setGeometry(QtCore.QRect(20, 80, 331, 20))
font = QtGui.QFont()
font.setPointSize(10)
self.including_2_special_characters.setFont(font)
self.including_2_special_characters.setText("")
self.including_2_special_characters.setObjectName("including_2_special_characters")
self.including_3_uppercase_characters = QtWidgets.QLabel(self.creating_the_password)
self.including_3_uppercase_characters.setGeometry(QtCore.QRect(20, 99, 331, 21))
font = QtGui.QFont()
font.setPointSize(10)
self.including_3_uppercase_characters.setFont(font)
self.including_3_uppercase_characters.setText("")
self.including_3_uppercase_characters.setObjectName("including_3_uppercase_characters")
self.including_4_lowercase_characters = QtWidgets.QLabel(self.creating_the_password)
self.including_4_lowercase_characters.setGeometry(QtCore.QRect(20, 120, 331, 20))
font = QtGui.QFont()
font.setPointSize(10)
self.including_4_lowercase_characters.setFont(font)
self.including_4_lowercase_characters.setText("")
self.including_4_lowercase_characters.setObjectName("including_4_lowercase_characters")
self.including_5_copy_the_password = QtWidgets.QLabel(self.creating_the_password)
self.including_5_copy_the_password.setGeometry(QtCore.QRect(20, 140, 331, 20))
font = QtGui.QFont()
font.setPointSize(10)
self.including_5_copy_the_password.setFont(font)
self.including_5_copy_the_password.setText("")
self.including_5_copy_the_password.setObjectName("including_5_copy_the_password")
self.including_6_save_password = QtWidgets.QLabel(self.creating_the_password)
self.including_6_save_password.setGeometry(QtCore.QRect(20, 160, 331, 20))
font = QtGui.QFont()
font.setPointSize(10)
self.including_6_save_password.setFont(font)
self.including_6_save_password.setText("")
self.including_6_save_password.setObjectName("including_6_save_password")
self.save_the_password_button = QtWidgets.QPushButton(self.creating_the_password)
self.save_the_password_button.setGeometry(QtCore.QRect(20, 280, 181, 31))
font = QtGui.QFont()
font.setPointSize(14)
self.save_the_password_button.setFont(font)
self.save_the_password_button.setObjectName("save_the_password_button")
self.including_7_location_label = QtWidgets.QLabel(self.creating_the_password)
self.including_7_location_label.setGeometry(QtCore.QRect(20, 240, 281, 20))
font = QtGui.QFont()
font.setPointSize(10)
self.including_7_location_label.setFont(font)
self.including_7_location_label.setText("")
self.including_7_location_label.setObjectName("including_7_location_label")
self.pushButton = QtWidgets.QPushButton(self.creating_the_password)
self.pushButton.setGeometry(QtCore.QRect(280, 280, 111, 31))
self.pushButton.setObjectName("pushButton")
self.length_label = QtWidgets.QLabel(self.creating_the_password)
self.length_label.setGeometry(QtCore.QRect(20, 190, 331, 20))
font = QtGui.QFont()
font.setPointSize(10)
self.length_label.setFont(font)
self.length_label.setText("")
self.length_label.setObjectName("length_label")
self.retranslateUi(Form)
self.pass_length.toggled['bool'].connect(self.by_writing.setVisible)
self.pass_length.toggled['bool'].connect(self.length_combobox.setVisible)
self.by_writing.toggled['bool'].connect(self.length_box.setVisible)
self.by_writing.toggled['bool'].connect(self.length_combobox.setVisible)
self.save_the_password.toggled['bool'].connect(self.location.setVisible)
self.save_the_password.toggled['bool'].connect(self.send_the_location.setVisible)
self.pass_length.toggled['bool'].connect(self.by_writing.setVisible)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Password Generator"))
self.Options.setTitle(_translate("Form", "Options"))
self.include_numbers.setText(_translate("Form", "Include numbers"))
self.special_characters.setText(_translate("Form", "Include special characters"))
self.pass_length.setText(_translate("Form", "Specify password length"))
self.uppercase.setText(_translate("Form", "Include uppercase characters"))
self.lower_case.setText(_translate("Form", "Include lowercase characters"))
self.length_combobox.setItemText(0, _translate("Form", "1"))
self.length_combobox.setItemText(1, _translate("Form", "2"))
self.length_combobox.setItemText(2, _translate("Form", "3"))
self.length_combobox.setItemText(3, _translate("Form", "4"))
self.length_combobox.setItemText(4, _translate("Form", "5"))
self.length_combobox.setItemText(5, _translate("Form", "6"))
self.length_combobox.setItemText(6, _translate("Form", "7"))
self.length_combobox.setItemText(7, _translate("Form", "8"))
self.length_combobox.setItemText(8, _translate("Form", "9"))
self.length_combobox.setItemText(9, _translate("Form", "10"))
self.length_combobox.setItemText(10, _translate("Form", "11"))
self.length_combobox.setItemText(11, _translate("Form", "12"))
self.length_combobox.setItemText(12, _translate("Form", "13"))
self.length_combobox.setItemText(13, _translate("Form", "14"))
self.length_combobox.setItemText(14, _translate("Form", "15"))
self.length_combobox.setItemText(15, _translate("Form", "16"))
self.length_combobox.setItemText(16, _translate("Form", "17"))
self.length_combobox.setItemText(17, _translate("Form", "18"))
self.length_combobox.setItemText(18, _translate("Form", "19"))
self.length_combobox.setItemText(19, _translate("Form", "20"))
self.by_writing.setText(_translate("Form", "I want to specify the length myself by writing"))
self.copy_the_password.setText(_translate("Form", "Copy the password to clipboard after creating"))
self.label.setText(_translate("Form", "{0,1,2,3,4,5,6,7,8,9}"))
self.label_2.setText(_translate("Form", "!\'^+%&/()>£#$"))
self.label_3.setText(_translate("Form", "A,B,C,D,E,F,G,H,I"))
self.label_4.setText(_translate("Form", "a,b,c,d,e,f,g,h,i"))
self.save_the_password.setText(_translate("Form", "Save the password to the location I tell the program"))
self.send_the_location.setText(_translate("Form", "Send the location"))
self.creating_the_password.setTitle(_translate("Form", "Creating the password"))
self.label_5.setText(_translate("Form", "Includings:"))
self.save_the_password_button.setText(_translate("Form", "Save the password "))
self.pushButton.setText(_translate("Form", "Create"))
# INTERFACE
#---------------------------------------------------------------------------
# CODES
class PasswordGenerator(QWidget):
def __init__(self):
super().__init__()
self.ui = Ui_Form()
self.ui.setupUi(self)
self.show()
self.ui.length_box.setVisible(0)
self.ui.length_combobox.setVisible(0)
self.ui.location.setVisible(0)
self.ui.send_the_location.setVisible(0)
self.ui.by_writing.setVisible(0)
self.ui.save_the_password_button.setVisible(0)
self.get_all = str()
self.isasked = False
self.ui.send_the_location.clicked.connect(self.xaaa)
self.ui.by_writing.toggled['bool'].connect(self.xaa)
self.ui.pass_length.toggled['bool'].connect(self.xab)
self.ui.length_box.textChanged.connect(self.xac)
self.ui.length_combobox.currentIndexChanged.connect(self.xaaab)
self.character_list_for_textbox_control = [
"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","r",
"s","t","u","w","v","x","y","z","ı","ğ","ü","ş","ö","ç",".",",","!",
"'",'"',"^","+","%","&","/","(",")","=","?","_","-","*","<",">","é",
"<","€","₩","₪","₫","€",">","£","#","$","½","{","[","]","}","\\","|"
]
self.lowercase_characters = "abcdefghijklmnoprstuvwxyz"; self.uppercase_characters = self.lowercase_characters.upper()
self.nums = "1234567890"
self.symbols = "!'^+%&/()=?_é>£#$½{[]}\|"
self.ui.include_numbers.toggled['bool'].connect(self.xad)
self.ui.special_characters.toggled['bool'].connect(self.xad)
self.ui.uppercase.toggled['bool'].connect(self.xad)
self.ui.lower_case.toggled['bool'].connect(self.xad)
self.ui.copy_the_password.toggled['bool'].connect(self.xad)
self.ui.save_the_password.toggled['bool'].connect(self.xad)
self.ui.save_the_password_button.clicked['bool'].connect(self.xag)
self.ui.send_the_location.clicked['bool'].connect(self.xae)
self.ui.pushButton.clicked.connect(self.xad)
self.ui.pushButton.clicked.connect(self.xaf)
showinfo("Information","If you do not specify any length value for your password, the default value is going to be 8.\nIf you do not select any options from the left side, The first four options on the left side are going to be used.")
def xaaa(self):
self.ui.save_the_password_button.setVisible(1 if self.ui.pushButton.clicked and self.ui.location.text() != "" and self.ui.location.text().startswith(("A:","B:","C:","D:","E:","F:","G:","H:","I:","J:","K:","L:","M:","N:","O:","P:","R:","S:","T:","U:","V:","W:","X:","Y:","Z:")) else 0)
self.ui.save_the_password_button.setEnabled(0)
def xaaab(self):
self.ui.length_label.setText(f"The length is: {self.ui.length_combobox.currentText()}")
def xaa(self):
self.ui.length_combobox.setVisible(0 if self.ui.length_combobox.isVisible() else 1)
self.ui.length_label.setText("")
if not self.ui.by_writing.isChecked():
self.ui.length_combobox.setCurrentIndex(0)
self.ui.length_box.setText("")
self.ui.length_label.setText(f"The length is: 1")
def xab(self):
self.ui.by_writing.setVisible(1 if self.ui.by_writing.isVisible() else 0)
[self.ui.length_box.setVisible(0), self.ui.by_writing.setChecked(0), self.ui.length_combobox.setVisible(0),self.ui.length_box.setText("")] if self.ui.by_writing.isChecked() else None
self.ui.length_label.setText(f"The length is: {self.ui.length_combobox.currentText()}")
if not self.ui.length_combobox.currentIndex() == 0:
self.ui.length_combobox.setCurrentIndex(0)
if not self.ui.pass_length.isChecked():
self.ui.length_label.setText("")
def xac(self):
for i in self.ui.length_box.text():
self.ui.length_box.setText("") if i.lower() in self.character_list_for_textbox_control else None
self.ui.length_label.setText(f"The length is: {self.ui.length_box.text()}") if not self.ui.length_box.text == "" and not self.ui.length_box.text().lower() in self.character_list_for_textbox_control else None
def xad(self):
self.ui.including_1_number.setText("Numbers included!" if self.ui.include_numbers.isChecked() else ""); self.number1_include_bool = True if self.ui.include_numbers.isChecked() else False
self.ui.including_2_special_characters.setText("Special characters included!" if self.ui.special_characters.isChecked() else ""); self.number2_specialcharacters_bool = True if self.ui.special_characters.isChecked() else False
self.ui.including_3_uppercase_characters.setText("Uppercase characters included!" if self.ui.uppercase.isChecked() else ""); self.number3_uppercase_bool = True if self.ui.uppercase.isChecked() else False
self.ui.including_4_lowercase_characters.setText("Lowercase characters included!" if self.ui.lower_case.isChecked() else ""); self.number4_lowercase_bool = True if self.ui.lower_case.isChecked() else False
self.ui.including_5_copy_the_password.setText("Copy the password to clipboard included!" if self.ui.copy_the_password.isChecked() else ""); self.number5_copypass_bool = True if self.ui.copy_the_password.isChecked() else False
self.ui.including_6_save_password.setText("Save the password to the location included!" if self.ui.save_the_password.isChecked() else ""); self.number6_save_bool = True if self.ui.save_the_password.isChecked() else False
def xae(self):
if not self.ui.location.text().startswith(("A:","B:","C:","D:","E:","F:","G:","H:","I:","J:","K:","L:","M:","N:","O:","P:","R:","S:","T:","U:","V:","W:","X:","Y:","Z:")):
showerror("Error","Please enter a location here!")
else:
if not self.ui.location.text().endswith("/"):
self.ui.including_7_location_label.setText(self.ui.location.text().replace("\\","/") + "/") if self.ui.location.text() != "" else None
else:
self.ui.including_7_location_label.setText(self.ui.location.text().replace("\\","/")) if self.ui.location.text() != "" else None
self.ui.location.setVisible(False)
self.ui.send_the_location.setVisible(False)
self.ui.save_the_password.setEnabled(False)
def xaf(self):
if self.isasked == False:
if self.ui.by_writing.isChecked():
if len(self.ui.length_box.text()) == 0:
showerror("Error!","You typed nothing to the length box!")
else:
ask = askyesno("Go?","Are you sure you want to continue\nand have you done your options from the left side?")
if ask:
self.ui.Options.setEnabled(0)
if self.ui.length_box.isVisible():
self.the_main_length = int(self.ui.length_box.text())
elif self.ui.length_combobox.isVisible():
ask2 = askyesno("Go?","Are you sure you want to continue\nand have you done your options from the left side?")
if int(self.ui.length_combobox.currentText()) <= 0:
showerror("Error","You did not select any length from the list!")
else:
if ask2:
self.ui.Options.setEnabled(0)
self.the_main_length = int(self.ui.length_combobox.currentText())
else:
ask3 = askyesno("Go?","Are you sure you want to continue?\nAnd have you done your options from the left side?\nThe default length value is going to be 8 because of you did not specify any length value for the password.")
if ask3:
self.ui.Options.setEnabled(0)
self.the_main_length = 8
self.get_all = str(self.nums + self.lowercase_characters + self.uppercase_characters + self.symbols)
self.ui.including_1_number.setText("Numbers included!")
self.ui.including_2_special_characters.setText("Special characters included!")
self.ui.including_3_uppercase_characters.setText("Uppercase characters included!")
self.ui.including_4_lowercase_characters.setText("Lowercase characters included!")
self.get_all = str(self.get_all + self.nums) if self.number1_include_bool is True else str(self.get_all)
self.get_all = str(self.get_all + self.symbols) if self.number2_specialcharacters_bool is True else str(self.get_all)
self.get_all = str(self.get_all + self.uppercase_characters) if self.number3_uppercase_bool is True else str(self.get_all)
self.get_all = str(self.get_all + self.lowercase_characters) if self.number4_lowercase_bool is True else str(self.get_all)
self.created_password = "".join(random.sample(self.get_all,self.the_main_length))
self.ui.save_the_password_button.setEnabled(1 if self.ui.save_the_password.isChecked else 0)
self.isasked = True
showinfo(f"Successful!","Your password has been created successfully!\nYour password is:" + self.created_password)
if self.ui.copy_the_password.isChecked():
copy(self.created_password)
showinfo("Copied.","The password copied to clipboard due to the box 'Copy to clipboard' is checked.")
else:
pass
return self.created_password
def xag(self):
if self.isasked == True:
with open(self.ui.location.text() + "/password.txt","w",encoding="utf-8") as f:
f.write(self.xaf())
if exists(self.ui.location.text() + "password.txt"):
showinfo("Successful!","The password being created on this program was successfully created for you in the location you specified!")
else:
showerror("Failed to create password. Please try again.")
if __name__ == "__main__":
app = QApplication(sys.argv)
w = PasswordGenerator()
sys.exit(app.exec_())
Son düzenleyen: Moderatör: