[5th] I tried to make a certain authenticator-like tool with python

A little failed (doesn't work)

――I will also post the one that has failed. ――This time, I cleaned the main operation part. --I modified it to operate the newly registered part from the menu at the top. --Menu> You can now close.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import tkinter as tk
import pyotp
import sqlite3
import os
import pyautogui
import sys

def create_table():
    #Connect to database
    conn = sqlite3.connect('gauth.db')
    c = conn.cursor()
    #Creating a table
    sql='''CREATE TABLE gauth
    (id integer primary key AUTOINCREMENT,
     name text,
     private_key text)'''

    c.execute(sql)
    #Save (commit) the inserted result
    conn.commit()
    #Close when you have finished accessing the database
    conn.close()

def view():
    #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()

def insert(id,username,private_key):
    #Connect to database
    conn = sqlite3.connect('gauth.db')
    c = conn.cursor()
    #Insert data
    c.execute(
        "INSERT INTO gauth VALUES (?,?,?)",(id,username,private_key))
    #Save (commit) the inserted result
    conn.commit()
    #Close when you have finished accessing the database
    conn.close()

def window_menu():
    #menu bar
    menubar = tk.Menu(root)
    filemenu = tk.Menu(menubar)
    filemenu.add_command(label="sign up", command=new)
    filemenu.add_command(label="Delete registration")
    filemenu.add_command(label="close", command=close)
    menubar.add_cascade(label="File", menu=filemenu)
    root.config(menu=menubar)

def new():
    pyautogui.prompt(text='user_name', title='user_name' , default='')
    pyautogui.prompt(text='private_key', title='private_key' , default='')
    #insert(user_name,private_key)

def close():
    sys.exit()

#Create window and title with tkinter
#Specify window size
root = tk.Tk()
root.title(u"g_authentication_tool")
root.geometry("300x200")
window_menu()
if(os.path.exists('gauth.db')):
    view()
else:
    create_table()
    #insert(1,"user1",'base32secret3232')
    view()
root.mainloop()

Recommended Posts

[5th] I tried to make a certain authenticator-like tool with python
[4th] I tried to make a certain authenticator-like tool with python
[2nd] I tried to make a certain authenticator-like tool with python
[3rd] 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 periodical process with CentOS7, Selenium, Python and Chrome
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
Rubyist tried to make a simple API with Python + bottle + MySQL
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
[1 hour challenge] I tried to make a fortune-telling site that is too suitable with Python
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