From 26902aa0b3b1ee0344d352252b41226f03cac3f3 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Sat, 8 Jun 2024 19:18:50 +0900 Subject: [PATCH] =?UTF-8?q?=E8=AA=8D=E8=A8=BC=E7=94=A8=E3=82=B5=E3=83=BC?= =?UTF-8?q?=E3=83=90=E3=83=BC=E3=81=AB=E3=81=A4=E3=81=AA=E3=81=90=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_client.py | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/dislocker_client.py b/dislocker_client.py index 9fb2798..ed9cde3 100644 --- a/dislocker_client.py +++ b/dislocker_client.py @@ -1,10 +1,11 @@ -import psycopg2 import os import json import customtkinter from winotify import Notification, audio import keyboard import subprocess +import requests +import hashlib class App(customtkinter.CTk): def __init__(self): @@ -89,15 +90,18 @@ class Lock(customtkinter.CTkToplevel): self.signin_button = customtkinter.CTkButton(self.button_frame, text='サインイン', command=self.auth) self.signin_button.grid(row=0, column=0, padx=10, pady=10) + def hash_genarate(self, source): + hashed = hashlib.md5(source.encode()) + return hashed.hexdigest() + def auth(self): - self.db = psycopg2.connect(f"host={db_config["host"]} dbname={db_config["db"]} port={db_config["port"]} user={db_config["username"]} password={db_config["password"]}") - cursor = self.db.cursor() - cursor.execute("SELECT * FROM pc_list WHERE pc_number = %s", (10,)) - pc_info = cursor.fetchall() - auth_password = str(self.password_entry.get()) - if pc_info[0][2] == auth_password: - cursor.execute("UPDATE pc_list SET password_hash = NULL WHERE pc_number = %s", (10,)) - self.db.commit() + auth_url = client_config["auth_host_url"] + "/verify" + auth_json = { + "pc_number": client_config["pc_number"], + "password": self.hash_genarate(self.password_entry.get()) + } + responce = requests.post(auth_url, json=auth_json) + if responce.status_code == 200: self.destroy() app.exit() else: @@ -111,22 +115,19 @@ class Lock(customtkinter.CTkToplevel): config_dir_path = "./config/" -db_config_path = config_dir_path + "db.json" -if not os.path.isfile(db_config_path): +client_config_path = config_dir_path + "client.json" +if not os.path.isfile(client_config_path): if not os.path.isdir(config_dir_path): os.mkdir(config_dir_path) - db_config = { - "host": "localhost", - "db": "dislocker", - "username": "user", - "password": "example_pass", - "port": "5432" + client_config = { + "auth_host_url": "localhost", + "pc_number": "" } - with open(db_config_path, "w") as w: - json.dump(db_config, w, indent=4) -elif os.path.isfile(db_config_path): - with open(db_config_path, "r") as r: + with open(client_config_path, "w") as w: + json.dump(client_config, w, indent=4) +elif os.path.isfile(client_config_path): + with open(client_config_path, "r") as r: db_config = json.load(r) if __name__ == '__main__':