--It doesn't work, but I added a menu. --Add functions. Or rather, the minimum functionality.
#!/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', 'SV6LSO55UOWQBYS7RFHVTY7KTUZSGRYN')")
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")
#menu bar
menubar = tk.Menu(root)
filemenu = tk.Menu(menubar)
filemenu.add_command(label="sign up")
filemenu.add_command(label="Delete registration")
filemenu.add_command(label="close")
menubar.add_cascade(label="File", menu=filemenu)
root.config(menu=menubar)
#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()
--Functional operation part of the menu --Organizing sources
Recommended Posts