Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Not the perfect code but it is working fine login form PyQt4
QtWS25 Last Chance

Not the perfect code but it is working fine login form PyQt4

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 412 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by p3c0
    #1
    import sys
    import os
    import mysql.connector
    from PyQt4.QtGui import *
    from PyQt4.QtCore import *
    from PyQt4.QtSql import *
    
    class Form(QDialog):
        def __init__(self, parent=None):
            super(Form,self).__init__(parent)
    
            self.db = QSqlDatabase.addDatabase("QMYSQL")
            self.db.setHostName("localhost")
            self.db.setDatabaseName("user")
            self.db.setUserName("root")
            self.db.setPassword("admingelo")
            self.db.open()
    
            self.username = QLineEdit(self)
            self.QUserLabel = QLabel("USERNAME")
    
            self.password = QLineEdit(self)
            self.QPasswordLabel = QLabel("PASSWORD")
            self.password.setEchoMode(QLineEdit.Password)
    
            self.btn_Submit = QPushButton("LOGIN")
    
            layout = QFormLayout()
            layout.addRow(self.QUserLabel,self.username)
            layout.addRow(self.QPasswordLabel,self.password)
            layout.addRow(self.btn_Submit)
    
            self.setLayout(layout)
    
            self.connect(self.btn_Submit, SIGNAL("clicked()"),self.Submit_btn)
    
        def Submit_btn(self):
            USERNAME = self.username.text()
            PASSWORD = self.password.text()
    
            self.query = QSqlQuery("SELECT username,password FROM users")
            while (self.query.next()):
                username = self.query.value(0).toString()
                password = self.query.value(1).toString()
    
            if USERNAME == username and PASSWORD == password:
                print "Login!"
            else:
                print "failed"
    
            
    app = QApplication(sys.argv)
    form = Form()
    form.show()
    app.exec_()
    

    Edit: Original post here: https://forum.qt.io/topic/75347/how-to-create-a-login-form-in-python-how-i-can-check-if-username-and-password-is-present-in-the-database-this-is-my-code

    1 Reply Last reply
    1
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @Gelo Thank you but it would be better if you post it into the original thread so that everything is connected. I will copy it into the original thread.

      157

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved