0

我正在尝试使用 rfid 和密码而不是常规的“1234”创建一个 python 智能锁,我将 Time OTP 与PyOTP Libray一起使用。

目前,我不知道如何使用来自表用户secret的数据在 if 函数中分配变量值。secret

如何将 secret用户表中的值分配给变量secret

如果函数

print("Place card near scanner")
id, text = reader.read()
cursor.execute("Select id From users Where rfid_uid="+str(id))
result = cursor.fetchone()

if cursor.rowcount > = 1:
   print("Welcome\nType the code from your authenticator app")
   secret = ('''The data from "secret" in users table''')

用户表

+----+--------------+-------------+------------------+---------------------+
| id | rfid_uid     | name        | secret           | created             |
+----+--------------+-------------+------------------+---------------------+
|  1 | 939940479059 | Blue Dongle | LONGSTRINGOFCODE | 2020-12-10 09:07:34 |
+----+--------------+-------------+------------------+---------------------+

谢谢你

4

1 回答 1

0

如果您修改 select 语句,您应该能够选择secret除了id.

print("Place card near scanner")
id, text = reader.read()
cursor.execute("SELECT id, secret FROM users WHERE rfid_uid="+str(id))
result = cursor.fetchone()

if cursor.rowcount >= 1:
    print("Welcome\nType the code from your authenticator app")
    secret = result[1]
于 2020-12-10T05:04:59.107 回答