LoginSignup
1
0

More than 3 years have passed since last update.

【第3回】pythonで某Authenticator的なツールを作ってみた

Posted at

メニューをつけた。

  • 機能はしないがメニューをつけた。
  • 機能を追加していく。というか最低限の機能。
#!/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:
    # データベースに接続する
    conn = sqlite3.connect('gauth.db')
    c = conn.cursor()
    # テーブルの作成
    c.execute(
        '''CREATE TABLE gauth(id integer primary key AUTOINCREMENT, name text, private_key text)''')
    # データの挿入
    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')")
    # 挿入した結果を保存(コミット)する
    conn.commit()
    # データベースへのアクセスが終わったら close する
    conn.close()
# tkinterでwindowの作成とタイトルを作る
# windowサイズの指定
root = tk.Tk()
root.title(u"g_authentication_tool")
root.geometry("300x200")
# メニューバー
menubar = tk.Menu(root)
filemenu = tk.Menu(menubar)
filemenu.add_command(label="新規登録")
filemenu.add_command(label="登録削除")
filemenu.add_command(label="閉じる")

menubar.add_cascade(label="ファイル", menu=filemenu)

root.config(menu=menubar)
# データベースに接続する
conn = sqlite3.connect('gauth.db')
c = conn.cursor()
for a in c.execute("select * from gauth"):
    totp = pyotp.TOTP(a[2])  # 鍵的な値
    totp.now()
    # 表示用ラベル
    Static1 = tk.Label(text=a[1])
    Static1.pack(side='left')

    Static2 = tk.Label(text=totp.now())
    Static2.pack(side='left')
    # 挿入した結果を保存(コミット)する
    conn.commit()
# データベースへのアクセスが終わったら close する
conn.close()
root.mainloop()

今後やっていくこと

  • メニューの機能動作部分
  • ソースの整理
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0