--Last time, you had to write the user information to the source as it is. --If there is no gauth.db file at the first execution, create it. --Users 1 to 3 are put in the DB with the INSERT INTO statement. --When executed, the authentication number at the moment of execution is displayed.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import tkinter as tk
import pyotp
import sqlite3
import os
if(os.path.exists('gauth.db')):
pass
else:
#Connect to database
conn = sqlite3.connect('gauth.db')
c = conn.cursor()
#Creating a table
c.execute('''CREATE TABLE gauth(id integer primary key AUTOINCREMENT, name text, private_key text)''')
#Insert data
c.execute("INSERT INTO gauth VALUES (1, 'user1', 'ZAQWSXCDERFVBGT')")
c.execute("INSERT INTO gauth VALUES (2, 'user2', 'qwertgfdsazxcvb')")
c.execute("INSERT INTO gauth VALUES (3, 'user3', 'vfrtgbnhyqweraa')")
#Save (commit) the inserted result
conn.commit()
#Close when you have finished accessing the database
conn.close()
#Create window and title with tkinter
#Specify window size
root = tk.Tk()
root.title(u"g_authentication_tool")
root.geometry("300x200")
#Connect to database
conn = sqlite3.connect('gauth.db')
c = conn.cursor()
for a in c.execute("select * from gauth"):
totp = pyotp.TOTP(a[2]) #Key value
totp.now()
#Label for display
Static1 = tk.Label(text=a[1])
Static1.pack(side='left')
Static2 = tk.Label(text=totp.now())
Static2.pack(side='left')
#Save (commit) the inserted result
conn.commit()
#Close when you have finished accessing the database
conn.close()
root.mainloop()
--Creating a new data registration part --Allow the authorization number to change over time
Recommended Posts