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. 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
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 4 Posters 11.7k 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.
  • p3c0P p3c0

    @Gelo Great so was that the exact cause ?

    ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #6

    @p3c0 i want my script to check if what i enter is on database then if not it will print nothing or query not exist

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

      @Gelo Sorry I'm not much aware of PyQt but here is an example:
      http://www.codeprogress.com/python/libraries/pyqt/showPyQTExample.php?index=422&key=QSqlDatabaseConnecttoMySql

      db 	= QSqlDatabase.addDatabase("QMYSQL")
      db.setHostName("10.30.0.30")
      db.setDatabaseName("testDB")
      db.setUserName("root")
      db.setPassword("password")
      
      query = QSqlQuery ("SELECT * FROM test") 
      while (query.next()):
          data = query.value(0).toString()
      

      You can try doing in the similar terms.

      157

      ? 1 Reply Last reply
      0
      • p3c0P p3c0

        @Gelo Sorry I'm not much aware of PyQt but here is an example:
        http://www.codeprogress.com/python/libraries/pyqt/showPyQTExample.php?index=422&key=QSqlDatabaseConnecttoMySql

        db 	= QSqlDatabase.addDatabase("QMYSQL")
        db.setHostName("10.30.0.30")
        db.setDatabaseName("testDB")
        db.setUserName("root")
        db.setPassword("password")
        
        query = QSqlQuery ("SELECT * FROM test") 
        while (query.next()):
            data = query.value(0).toString()
        

        You can try doing in the similar terms.

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #8

        @p3c0 Thank you for your help i already solve the problem :)

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

          @Gelo Congratulations :) You can post the updated rectified code so that it might be helpful for others in the future.

          157

          ? 1 Reply Last reply
          0
          • p3c0P p3c0

            @Gelo Congratulations :) You can post the updated rectified code so that it might be helpful for others in the future.

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #10

            @p3c0 Yeah sure :) Thank you my friend!

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

              Updated working code by @Gelo :

              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_()
              

              157

              1 Reply Last reply
              1
              • J Offline
                J Offline
                jayrawatrj
                wrote on last edited by
                #12

                self.connect(self.btn_Submit, SIGNAL("clicked()"),self.Submit_btn)

                what is "SIGNAL" here,??

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #13

                  Hi and welcome to devnet,

                  Please take a look at the new syntax documentation.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jayrawatrj
                    wrote on last edited by jayrawatrj
                    #14

                    thanks or reply.. instead of SIGNAL now we are using pyqtSignal() but here SIGNAL("clicked()") instead of clicked() what should i pass cause clicked () is giving error as

                    ""self.btn_Submit.clicked.connect(pyqtSignal('clicked'),self.Submit_btn)

                    TypeError: C++ type 'clicked' is not supported as a pyqtSignal() type argument type ""

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #15

                      Did you read PyQt's New-style Signal and Slot Support ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0

                      • Login

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