Python Forum
PyQt5 How do you make a functioning login and registration program?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyQt5 How do you make a functioning login and registration program?
#1
Hello! I am trying to make a User login and register program involving an sqlite3 database, but Im having trouble where to began nor what to do. Heres a snippet of my code for my registration form.

class Ui_RegisterForm(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(531, 345)
        self.Usernameedit = QtWidgets.QLineEdit(Form)
        self.Usernameedit.setGeometry(QtCore.QRect(170, 70, 261, 31))
        self.Usernameedit.setObjectName("Usernameedit")
        self.Passwordedit = QtWidgets.QLineEdit(Form)
        self.Passwordedit.setGeometry(QtCore.QRect(170, 140, 261, 31))
        self.Passwordedit.setObjectName("Passwordedit")
        self.Passwordedit.setEchoMode(QtWidgets.QLineEdit.Password)
        self.confirmPasswordedit = QtWidgets.QLineEdit(Form)
        self.confirmPasswordedit.setGeometry(QtCore.QRect(170, 210, 261, 31))
        self.confirmPasswordedit.setObjectName("confirmPasswordedit")
        self.confirmPasswordedit.setEchoMode(QtWidgets.QLineEdit.Password)
        self.confirmButton = QtWidgets.QPushButton(Form)
        self.confirmButton.setGeometry(QtCore.QRect(180, 280, 93, 28))
        self.confirmButton.setObjectName("confirmButton")
        self.cancelButton = QtWidgets.QPushButton(Form)
        self.cancelButton.setGeometry(QtCore.QRect(340, 280, 93, 28))
        self.cancelButton.setObjectName("cancelButton")
        self.cancelButton.clicked.connect(Controller.CloseRegister)
        self.label = QtWidgets.QLabel(Form)
        self.label.setGeometry(QtCore.QRect(90, 70, 71, 20))
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(Form)
        self.label_2.setGeometry(QtCore.QRect(90, 140, 61, 20))
        self.label_2.setObjectName("label_2")
        self.label_3 = QtWidgets.QLabel(Form)
        self.label_3.setGeometry(QtCore.QRect(40, 210, 111, 20))
        self.label_3.setObjectName("label_3")

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Make a new account", "Form"))
        self.confirmButton.setText(_translate("Make a new account", "Confirm"))
        self.cancelButton.setText(_translate("Make a new account", "Cancel"))
        self.label.setText(_translate("Make a new account", "Username"))
        self.label_2.setText(_translate("Make a new account", "Password"))
        self.label_3.setText(_translate("Make a new account", "Confirm Password"))
I felt that giving my login registration code wasn't necessary but if needed I could.

Im not sure how to add in tags to the post too...
Reply
#2
I don't really know what your question is.
You seem to be using QtDesigner, it is usually a problem to change such files afterwards.

This is how it could look like without QtDesigner.

from PyQt5.QtWidgets import (QLineEdit, QApplication, QWidget, QPushButton, 
                            QVBoxLayout, QHBoxLayout, QMessageBox)

class Ui_RegisterForm(QWidget):
    def __init__(self):
        super(Ui_RegisterForm, self).__init__()
        self.setupUi()
    
    def setupUi(self):
        self.setFixedSize(300, 200)
        self.setWindowTitle("Make a new account")
        
        self.Usernameedit = QLineEdit()
        self.Passwordedit = QLineEdit()
        self.confirmPasswordedit = QLineEdit()
        self.Passwordedit.setEchoMode(QLineEdit.Password)
        self.confirmPasswordedit.setEchoMode(QLineEdit.Password)
        
        self.confirmButton = QPushButton()
        self.cancelButton = QPushButton()
        self.confirmButton.clicked.connect(self.getValues)
        self.cancelButton.clicked.connect(lambda: self.close())

        self.confirmButton.setText("Confirm")
        self.cancelButton.setText("Cancel")
        self.Usernameedit.setPlaceholderText("Username")
        self.Passwordedit.setPlaceholderText("Password")
        self.confirmPasswordedit.setPlaceholderText("Confirm Password")
        self.confirmPasswordedit.returnPressed.connect(self.getValues)
        
        vbox = QVBoxLayout()
        hbox = QHBoxLayout()
        vbox.addWidget(self.Usernameedit)
        vbox.addWidget(self.Passwordedit)
        vbox.addWidget(self.confirmPasswordedit)
        hbox.addWidget(self.cancelButton)
        hbox.addWidget(self.confirmButton)
        vbox.addLayout(hbox)
        self.setLayout(vbox)
        
    def getValues(self):
        if self.Passwordedit.text() == self.confirmPasswordedit.text():
            values = [self.Usernameedit.text(), self.Passwordedit.text(), self.confirmPasswordedit.text()]
            # use the values for the next step
            print(values) # for testing only
            self.close()
        else:
            msg = QMessageBox.warning(None, "Error", "passwords not matching" )
            return
            
    
if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)
    mainWin = Ui_RegisterForm()
    mainWin.show()
    sys.exit(app.exec_())
Reply
#3
(Dec-25-2019, 09:58 AM)Axel_Erfurt Wrote: I don't really know what your question is. You seem to be using QtDesigner, it is usually a problem to change such files afterwards. This is how it could look like without QtDesigner.
 from PyQt5.QtWidgets import (QLineEdit, QApplication, QWidget, QPushButton, QVBoxLayout, QHBoxLayout, QMessageBox) class Ui_RegisterForm(QWidget): def __init__(self): super(Ui_RegisterForm, self).__init__() self.setupUi() def setupUi(self): self.setFixedSize(300, 200) self.setWindowTitle("Make a new account") self.Usernameedit = QLineEdit() self.Passwordedit = QLineEdit() self.confirmPasswordedit = QLineEdit() self.Passwordedit.setEchoMode(QLineEdit.Password) self.confirmPasswordedit.setEchoMode(QLineEdit.Password) self.confirmButton = QPushButton() self.cancelButton = QPushButton() self.confirmButton.clicked.connect(self.getValues) self.cancelButton.clicked.connect(lambda: self.close()) self.confirmButton.setText("Confirm") self.cancelButton.setText("Cancel") self.Usernameedit.setPlaceholderText("Username") self.Passwordedit.setPlaceholderText("Password") self.confirmPasswordedit.setPlaceholderText("Confirm Password") self.confirmPasswordedit.returnPressed.connect(self.getValues) vbox = QVBoxLayout() hbox = QHBoxLayout() vbox.addWidget(self.Usernameedit) vbox.addWidget(self.Passwordedit) vbox.addWidget(self.confirmPasswordedit) hbox.addWidget(self.cancelButton) hbox.addWidget(self.confirmButton) vbox.addLayout(hbox) self.setLayout(vbox) def getValues(self): if self.Passwordedit.text() == self.confirmPasswordedit.text(): values = [self.Usernameedit.text(), self.Passwordedit.text(), self.confirmPasswordedit.text()] # use the values for the next step print(values) # for testing only self.close() else: msg = QMessageBox.warning(None, "Error", "passwords not matching" ) return if __name__ == '__main__': import sys app = QApplication(sys.argv) mainWin = Ui_RegisterForm() mainWin.show() sys.exit(app.exec_()) 
This helped out alot. Thank you!
Reply
#4
@YoshikageKira I have not delved into this too deeply and I think I might have mentioned this to you elsewhere looking to MVC methodology because down the road having your frontend talking directly to your backend like it seems you might be doing is only going to be painful. I will gladly help you understand how to use MVC methodology and I can even supply a database template that I made for my python-pyqt students (whom I tutor for free) and I share that with you as well
Reply
#5
@Denni

You recently made an offer to share some tutorial information to the OP of this thread. If you are willing to share with others, I would also be very interested in seeing that material.

Thank you in advance.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I run an interface I made using PyQt5 and a Map program I made using Tkinter bki 6 1,046 Nov-09-2023, 11:12 PM
Last Post: bki
  [PyQt] Pyqt5: How do you make a button that adds new row with data to a Qtablewidget YoshikageKira 6 6,876 Jan-02-2020, 04:32 PM
Last Post: Denni
  Huge code problems (buttons(PyQt5),PyQt5 Threads, Windows etc) ZenWoR 0 2,785 Apr-06-2019, 11:15 PM
Last Post: ZenWoR
  Make a fully functional program as a library frequency 3 2,589 Dec-26-2018, 12:18 PM
Last Post: frequency

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020