PyQt5: chapter9-Create login form-Apply authentication process

Instance

  1. Create a template window based on Dialog without Buttons
  2. Add three Labels, two LineEdits, and a PushButton component
  3. Set the text of the first two Labels to Email Address, Password
  4. Set the text of the third Label to be empty
  5. Set the text of PushButton to Sign In
  6. Set the objectName of Line Edit to lineEditEmailAddress, lineEditPassword
  7. Set the objectName of PushButton to pushButtonSearch
  8. Set the object Name of the third Label to labelResponse
  9. Save as demoSignInForm.ui
  10. Use pyuic to generate demoSignInForm.py
  11. Create callSignInForm.py, the code is as follows
import sys,sqlite3
from PyQt5.QtWidgets import QDialog,QApplication
from sqlite3 import Error
from cookbook_200504.demoSearchRows import *

class MyForm(QDialog):
    def __init__(self):
        super().__init__()
        self.ui=Ui_Dialog()
        self.ui.setupUi(self)
        self.ui.pushButtonSearch.clicked.connect(self.SearchRows)
        self.show()
    def SearchRows(self):
        sqlStatement="SELECT Password FROM "+self.ui.lineEditTableName.text()+" WHERE EmailAddress LIKE'"+self.ui.lineEditEmailAddress.text()+"';"
        try:
            conn=sqlite3.connect(self.ui.lineEditDBName.text()+".db")
            cur=conn.cursor()
            cur.execute(sqlStatement)
            row=cur.fetchone()
            if row==None:
                self.ui.labelResponse.setText("Sorry, No User found with this email address")
                self.ui.lineEditPassword.setText("")
            else:
                self.ui.labelResponse.setText("Email Address Found, Password of this User is :")
                self.ui.lineEditPassword.setText(row[0])
        except Error as e:
            self.ui.labelResponse.setText("Error in accessing row")
        finally:
            conn.close()
if __name__=="__main__":
    app=QApplication(sys.argv)
    w=MyForm()
    w.show()
    sys.exit(app.exec())

 

Guess you like

Origin blog.csdn.net/weixin_43307431/article/details/105924713