[2nd] I tried to make a certain authenticator-like tool with python

I tried to make the user information to be displayed into a DB.

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

Next time

--Creating a new data registration part --Allow the authorization number to change over time

Recommended Posts

[2nd] I tried to make a certain authenticator-like tool with python
[3rd] I tried to make a certain authenticator-like tool with python
[4th] I tried to make a certain authenticator-like tool with python
[1st] I tried to make a certain authenticator-like tool with python
I tried to make a periodical process with Selenium and Python
I tried to make a 2channel post notification application with Python
I tried to make a todo application using bottle with python
I want to make a game with Python
Python: I tried to make a flat / flat_map just right with a generator
I tried to make a traffic light-like with Raspberry Pi 4 (Python edition)
Try to make a command standby tool with python
I tried to draw a route map with Python
I tried to automatically generate a password with Python3
I tried to make a simple mail sending application with tkinter of Python
[Patent analysis] I tried to make a patent map with Python without spending money
I tried to make various "dummy data" with Python faker
[Python] When I tried to make a decompression tool with a zip file I just knew, I was addicted to sys.exit ()
I tried to make a stopwatch using tkinter in python
I tried to make GUI tic-tac-toe with Python and Tkinter
I tried to make a real-time sound source separation mock with Python machine learning
I tried a functional language with Python
I tried to make a Web API
I tried to make a regular expression of "amount" using Python
[Python] I tried to implement stable sorting, so make a note
I tried to make a regular expression of "time" using Python
[Python] A memo that I tried to get started with asyncio
I tried to create a list of prime numbers with python
I tried to make a regular expression of "date" using Python
[Introduction] I want to make a Mastodon Bot with Python! 【Beginners】
[Python] Simple Japanese ⇒ I tried to make an English translation tool
I tried to make a strange quote for Jojo with LSTM
I tried to make an image similarity function with Python + OpenCV
I tried to make a mechanism of exclusive control with Go
I tried to make a generator that generates a C # container class from CSV with Python
I tried to get CloudWatch data with Python
Try to make a "cryptanalysis" cipher with Python
I tried to output LLVM IR with Python
I tried to automate sushi making with python
Try to make a dihedral group with Python
I tried running alembic, a Python migration tool
I want to write to a file with Python
I tried to make a ○ ✕ game using TensorFlow
I tried to communicate with a remote server by Socket communication with Python.
I made a tool to automatically browse multiple sites with Selenium (Python)
I tried to create a program to convert hexadecimal numbers to decimal numbers with python
I tried to make a calculator with Tkinter so I will write it
I tried to make "Sakurai-san" a LINE BOT with API Gateway + Lambda
[AWS] [GCP] I tried to make cloud services easy to use with Python
I tried to discriminate a 6-digit number with a number discrimination application made with python
[Outlook] I tried to automatically create a daily report email with Python
I tried to build a Mac Python development environment with pythonz + direnv
A note I looked up to make a command line tool in Python
[Zaif] I tried to make it easy to trade virtual currencies with Python
I tried to make a url shortening service serverless with AWS CDK
I tried fp-growth with python
I tried to make a "fucking big literary converter"
I tried scraping with Python
I tried to create a table only with Django
I tried to implement Minesweeper on terminal with python
I tried to get started with blender python script_Part 01
I tried to touch the CSV file with Python