# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'V 0.1.ui'
#
# Created by: PyQt5 UI code generator 5.15.0
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets
import csv
import random


#These are lists of characters that program can use to generate password
smlLetters = ["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"]

capLetters = ["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"]

numbers = ["1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "0"]
symbols = ["!" , "@" , "#" , "$" , "%"]


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.lopDescription1 = QtWidgets.QTextEdit(self.centralwidget)
        self.lopDescription1.setGeometry(QtCore.QRect(10, 30, 191, 41))
        self.lopDescription1.setStatusTip("")
        self.lopDescription1.setReadOnly(True)
        self.lopDescription1.setPlaceholderText("")
        self.lopDescription1.setObjectName("lopDescription1")
        self.nopDescription1 = QtWidgets.QTextEdit(self.centralwidget)
        self.nopDescription1.setGeometry(QtCore.QRect(10, 80, 181, 41))
        self.nopDescription1.setReadOnly(True)
        self.nopDescription1.setObjectName("nopDescription1")
        self.generateButton = QtWidgets.QPushButton(self.centralwidget)
        self.generateButton.setGeometry(QtCore.QRect(250, 380, 251, 121))
        font = QtGui.QFont()
        font.setPointSize(36)
        self.generateButton.setFont(font)
        self.generateButton.setObjectName("generateButton")
        self.lopDescription1_2 = QtWidgets.QTextEdit(self.centralwidget)
        self.lopDescription1_2.setGeometry(QtCore.QRect(320, 30, 291, 41))
        self.lopDescription1_2.setStatusTip("")
        self.lopDescription1_2.setReadOnly(True)
        self.lopDescription1_2.setPlaceholderText("")
        self.lopDescription1_2.setObjectName("lopDescription1_2")
        self.nopDescription2 = QtWidgets.QTextEdit(self.centralwidget)
        self.nopDescription2.setGeometry(QtCore.QRect(320, 80, 291, 41))
        self.nopDescription2.setReadOnly(True)
        self.nopDescription2.setObjectName("nopDescription2")
        self.nameOfPassword = QtWidgets.QLineEdit(self.centralwidget)
        self.nameOfPassword.setGeometry(QtCore.QRect(200, 90, 113, 28))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.nameOfPassword.setFont(font)
        self.nameOfPassword.setMaxLength(50)
        self.nameOfPassword.setObjectName("nameOfPassword")
        self.lenOfPassword = QtWidgets.QSpinBox(self.centralwidget)
        self.lenOfPassword.setGeometry(QtCore.QRect(210, 30, 91, 28))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.lenOfPassword.setFont(font)
        self.lenOfPassword.setMinimum(1)
        self.lenOfPassword.setMaximum(4096)
        self.lenOfPassword.setObjectName("lenOfPassword")
        self.useNumbers = QtWidgets.QCheckBox(self.centralwidget)
        self.useNumbers.setGeometry(QtCore.QRect(20, 140, 141, 41))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.useNumbers.setFont(font)
        self.useNumbers.setChecked(True)
        self.useNumbers.setObjectName("useNumbers")
        self.useSmlLetters = QtWidgets.QCheckBox(self.centralwidget)
        self.useSmlLetters.setGeometry(QtCore.QRect(20, 290, 161, 41))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.useSmlLetters.setFont(font)
        self.useSmlLetters.setIconSize(QtCore.QSize(100, 100))
        self.useSmlLetters.setChecked(True)
        self.useSmlLetters.setObjectName("useSmlLetters")
        self.useSymbols = QtWidgets.QCheckBox(self.centralwidget)
        self.useSymbols.setGeometry(QtCore.QRect(20, 240, 131, 41))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.useSymbols.setFont(font)
        self.useSymbols.setChecked(True)
        self.useSymbols.setObjectName("useSymbols")
        self.useCapLetters = QtWidgets.QCheckBox(self.centralwidget)
        self.useCapLetters.setGeometry(QtCore.QRect(20, 190, 191, 41))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.useCapLetters.setFont(font)
        self.useCapLetters.setChecked(True)
        self.useCapLetters.setTristate(False)
        self.useCapLetters.setObjectName("useCapLetters")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        self.generateButton.clicked.connect(self.genpass)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        #set app icon
        app_icon = QtGui.QIcon()
        app_icon.addFile('./icons/16x16.png', QtCore.QSize(16,16))
        app_icon.addFile('./icons/24x24.png', QtCore.QSize(24,24))
        app_icon.addFile('./icons/32x32.png', QtCore.QSize(32,32))
        app_icon.addFile('./icons/48x48.png', QtCore.QSize(48,48))
        app_icon.addFile('./icons/256x256.png', QtCore.QSize(256,256))
        app.setWindowIcon(app_icon)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("Password Generator", "Password Generator"))
        self.lopDescription1.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Noto Sans\'; font-size:10pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:16pt;\">Length of password:</span></p></body></html>"))
        self.nopDescription1.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Noto Sans\'; font-size:10pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:16pt;\">Name of password:</span></p></body></html>"))
        self.generateButton.setText(_translate("MainWindow", "Generate"))
        self.lopDescription1_2.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Noto Sans\'; font-size:10pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:16pt;\">Maimum length is 4096 character</span></p></body></html>"))
        self.nopDescription2.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Noto Sans\'; font-size:10pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:16pt;\">Maximum length is 50 character</span></p></body></html>"))
        self.useNumbers.setText(_translate("MainWindow", "Use numbers"))
        self.useSmlLetters.setText(_translate("MainWindow", "Use small letters"))
        self.useSymbols.setText(_translate("MainWindow", "Use symbols"))
        self.useCapLetters.setText(_translate("MainWindow", "Use cappital letters"))


    #genpass function generate password.
    def genpass(self):
        #This is password. every time program choose character for password program add character to password string.
        password = ""

        #This is list of characters that program can use
        liOfChars = []
        #Add list that user choose to liOfChars
        if self.useNumbers.isChecked() == True:
            liOfChars.append(numbers)
        if self.useSymbols.isChecked() == True:
            liOfChars.append(symbols)
        if self.useCapLetters.isChecked() == True:
            liOfChars.append(capLetters)
        if self.useSmlLetters.isChecked() == True:
            liOfChars.append(smlLetters)

        #Check if user choose name for password and choose at least one option for password then start generating password
        if self.nameOfPassword.text() != "" and liOfChars != []:
            for char in range(int(self.lenOfPassword.text())):
                #choose characters
                choosingList = liOfChars[(random.randrange(0 , (liOfChars.index(liOfChars[-1]) + 1)))]
                choosingChar = choosingList[(random.randrange(0 , (choosingList.index(choosingList[-1]) + 1)))]
                password += choosingChar

            #write password in file.txt
            with open("./file.csv" , "a") as csvFile:
                csvReader = csv.reader(csvFile)
                csvWriter = csv.writer(csvFile)
                password = [self.nameOfPassword.text() , password]
                csvWriter.writerow(password)


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'V 0.1.ui'
#
# Created by: PyQt5 UI code generator 5.15.0
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets
import csv
import random


#These are lists of characters that program can use to generate password
smlLetters = ["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"]

capLetters = ["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"]

numbers = ["1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "0"]
symbols = ["!" , "@" , "#" , "$" , "%"]


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.lopDescription1 = QtWidgets.QTextEdit(self.centralwidget)
        self.lopDescription1.setGeometry(QtCore.QRect(10, 30, 191, 41))
        self.lopDescription1.setStatusTip("")
        self.lopDescription1.setReadOnly(True)
        self.lopDescription1.setPlaceholderText("")
        self.lopDescription1.setObjectName("lopDescription1")
        self.nopDescription1 = QtWidgets.QTextEdit(self.centralwidget)
        self.nopDescription1.setGeometry(QtCore.QRect(10, 80, 181, 41))
        self.nopDescription1.setReadOnly(True)
        self.nopDescription1.setObjectName("nopDescription1")
        self.generateButton = QtWidgets.QPushButton(self.centralwidget)
        self.generateButton.setGeometry(QtCore.QRect(250, 380, 251, 121))
        font = QtGui.QFont()
        font.setPointSize(36)
        self.generateButton.setFont(font)
        self.generateButton.setObjectName("generateButton")
        self.lopDescription1_2 = QtWidgets.QTextEdit(self.centralwidget)
        self.lopDescription1_2.setGeometry(QtCore.QRect(320, 30, 291, 41))
        self.lopDescription1_2.setStatusTip("")
        self.lopDescription1_2.setReadOnly(True)
        self.lopDescription1_2.setPlaceholderText("")
        self.lopDescription1_2.setObjectName("lopDescription1_2")
        self.nopDescription2 = QtWidgets.QTextEdit(self.centralwidget)
        self.nopDescription2.setGeometry(QtCore.QRect(320, 80, 291, 41))
        self.nopDescription2.setReadOnly(True)
        self.nopDescription2.setObjectName("nopDescription2")
        self.nameOfPassword = QtWidgets.QLineEdit(self.centralwidget)
        self.nameOfPassword.setGeometry(QtCore.QRect(200, 90, 113, 28))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.nameOfPassword.setFont(font)
        self.nameOfPassword.setMaxLength(50)
        self.nameOfPassword.setObjectName("nameOfPassword")
        self.lenOfPassword = QtWidgets.QSpinBox(self.centralwidget)
        self.lenOfPassword.setGeometry(QtCore.QRect(210, 30, 91, 28))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.lenOfPassword.setFont(font)
        self.lenOfPassword.setMinimum(1)
        self.lenOfPassword.setMaximum(4096)
        self.lenOfPassword.setObjectName("lenOfPassword")
        self.useNumbers = QtWidgets.QCheckBox(self.centralwidget)
        self.useNumbers.setGeometry(QtCore.QRect(20, 140, 141, 41))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.useNumbers.setFont(font)
        self.useNumbers.setChecked(True)
        self.useNumbers.setObjectName("useNumbers")
        self.useSmlLetters = QtWidgets.QCheckBox(self.centralwidget)
        self.useSmlLetters.setGeometry(QtCore.QRect(20, 290, 161, 41))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.useSmlLetters.setFont(font)
        self.useSmlLetters.setIconSize(QtCore.QSize(100, 100))
        self.useSmlLetters.setChecked(True)
        self.useSmlLetters.setObjectName("useSmlLetters")
        self.useSymbols = QtWidgets.QCheckBox(self.centralwidget)
        self.useSymbols.setGeometry(QtCore.QRect(20, 240, 131, 41))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.useSymbols.setFont(font)
        self.useSymbols.setChecked(True)
        self.useSymbols.setObjectName("useSymbols")
        self.useCapLetters = QtWidgets.QCheckBox(self.centralwidget)
        self.useCapLetters.setGeometry(QtCore.QRect(20, 190, 191, 41))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.useCapLetters.setFont(font)
        self.useCapLetters.setChecked(True)
        self.useCapLetters.setTristate(False)
        self.useCapLetters.setObjectName("useCapLetters")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        self.generateButton.clicked.connect(self.genpass)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        #set app icon
        app_icon = QtGui.QIcon()
        app_icon.addFile('./icons/16x16.png', QtCore.QSize(16,16))
        app_icon.addFile('./icons/24x24.png', QtCore.QSize(24,24))
        app_icon.addFile('./icons/32x32.png', QtCore.QSize(32,32))
        app_icon.addFile('./icons/48x48.png', QtCore.QSize(48,48))
        app_icon.addFile('./icons/256x256.png', QtCore.QSize(256,256))
        app.setWindowIcon(app_icon)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("Password Generator", "Password Generator"))
        self.lopDescription1.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Noto Sans\'; font-size:10pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:16pt;\">Length of password:</span></p></body></html>"))
        self.nopDescription1.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Noto Sans\'; font-size:10pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:16pt;\">Name of password:</span></p></body></html>"))
        self.generateButton.setText(_translate("MainWindow", "Generate"))
        self.lopDescription1_2.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Noto Sans\'; font-size:10pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:16pt;\">Maimum length is 4096 character</span></p></body></html>"))
        self.nopDescription2.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Noto Sans\'; font-size:10pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:16pt;\">Maximum length is 50 character</span></p></body></html>"))
        self.useNumbers.setText(_translate("MainWindow", "Use numbers"))
        self.useSmlLetters.setText(_translate("MainWindow", "Use small letters"))
        self.useSymbols.setText(_translate("MainWindow", "Use symbols"))
        self.useCapLetters.setText(_translate("MainWindow", "Use cappital letters"))


    #genpass function generate password.
    def genpass(self):
        #This is password. every time program choose character for password program add character to password string.
        password = ""

        #This is list of characters that program can use
        liOfChars = []
        #Add list that user choose to liOfChars
        if self.useNumbers.isChecked() == True:
            liOfChars.append(numbers)
        if self.useSymbols.isChecked() == True:
            liOfChars.append(symbols)
        if self.useCapLetters.isChecked() == True:
            liOfChars.append(capLetters)
        if self.useSmlLetters.isChecked() == True:
            liOfChars.append(smlLetters)

        #Check if user choose name for password and choose at least one option for password then start generating password
        if self.nameOfPassword.text() != "" and liOfChars != []:
            for char in range(int(self.lenOfPassword.text())):
                #choose characters
                choosingList = liOfChars[(random.randrange(0 , (liOfChars.index(liOfChars[-1]) + 1)))]
                choosingChar = choosingList[(random.randrange(0 , (choosingList.index(choosingList[-1]) + 1)))]
                password += choosingChar

            #write password in file.txt
            with open("./file.csv" , "a") as csvFile:
                csvReader = csv.reader(csvFile)
                csvWriter = csv.writer(csvFile)
                password = [self.nameOfPassword.text() , password]
                csvWriter.writerow(password)


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'V 0.1.ui' # # Created by: PyQt5 UI code generator 5.15.0 # # WARNING: Any manual changes made to this file will be lost when pyuic5 is # run again.  Do not edit this file unless you know what you are doing. #These are lists of characters that program can use to generate password #set app icon #genpass function generate password. #This is password. every time program choose character for password program add character to password string. #This is list of characters that program can use #Add list that user choose to liOfChars #Check if user choose name for password and choose at least one option for password then start generating password #choose characters #write password in file.txt