#!/usr/bin/python import MySQLdb import getpass print("-------------------------") print("<<<<<<<<<Welcome>>>>>>>>>") print("-------------------------") username = input("Username:") if username == "username" : password = getpass.getpass(prompt="Enter secret password:") else : print ("please try another user name. This user name is incorrect") print password # Open database connection db = MySQLdb.connect("hostname","user,"pass","db" ) # prepare a cursor object using cursor() method cursor = db.cursor() # execute SQL query using execute() method. cursor.execute("SELECT userID, password from db") # Fetch a single row using fetchone() method. data = cursor.fetchone() # disconnect from server db.close()
Мне нужно сравнить введенные значения username и password со значениями userID и password из БД.
Структура таблицы permissions:
id int(11) Автоматическое приращение userID bigint(12) unsigned password varchar(32) PointsQuota tinyint(3) Period tinyint(2) deviceID char(17) user_phone bigint(20) email varchar(128) enable tinyint(2) ssh_port int(5)
ОС Ubuntu 20.04, Python 3.8.