0

I'm trying to create a python smart lock thing using rfid and the password instead of regular "1234", I'm using Time OTP with PyOTP Libray.

At the moment I'm stuck with how to assign the secret variable value at the if function using data from secret from table users.

How do I do assign the secret value from users table to the variable secret

IF FUNCTION

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''')

users Table

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

Thank You

Al-
  • 27
  • 7

1 Answers1

0

If you modify the select statement you should be able to select the secret in addition to the 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]
Alex Watt
  • 927
  • 5
  • 14
  • It said `No result set to fetch from` from the `rows = cursor.fetchall()` But when I edited `result = cursor.fetchone()` to `fetchall()` and change the line after the `print` to only `secret = result[1]` it respond with `index out of range`,and if its `secret = result[0]` it simply respond with print `id` and `secret`. Any idea why it happend? Thank you for your answer. – Al- Dec 10 '20 at 08:39
  • Ah, I updated my answer. Once fetchone() is called, fetchall() can't grab the result that was already fetched. – Alex Watt Dec 10 '20 at 11:56