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
-
@Gelo Great so was that the exact cause ?
-
@p3c0 it just print this instead to check if what i enter do exist
RESTART: C:/Users/angelo/Desktop/IMS Delta EarthMoving Incorporated/QtLogin.py
SELECT username FROM users WHERE username = 'admin'
SELECT password FROM users WHERE password = 'password' -
@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
-
@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=QSqlDatabaseConnecttoMySqldb = 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.
-
@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=QSqlDatabaseConnecttoMySqldb = 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.
@p3c0 Thank you for your help i already solve the problem :)
-
@Gelo Congratulations :) You can post the updated rectified code so that it might be helpful for others in the future.
-
@Gelo Congratulations :) You can post the updated rectified code so that it might be helpful for others in the future.
@p3c0 Yeah sure :) Thank you my friend!
-
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_()
-
self.connect(self.btn_Submit, SIGNAL("clicked()"),self.Submit_btn)
what is "SIGNAL" here,??
-
Hi and welcome to devnet,
Please take a look at the new syntax documentation.
-
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 ""
-
Did you read PyQt's New-style Signal and Slot Support ?