Skip to content

Commit

Permalink
Added hash auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Red_wolf2467 committed Nov 17, 2024
1 parent 4a54009 commit 0da2749
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
10 changes: 10 additions & 0 deletions create_hash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import hashlib

def hash_string(string):
hashed = hashlib.sha256(string.encode()).hexdigest()
return hashed

input_string = input("Enter Text: ")

hashed_output = hash_string(input_string)
print(f"Hash: {hashed_output}")
1 change: 1 addition & 0 deletions key_hash.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
25 changes: 24 additions & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
from quart import Quart, request
from colorama import Fore, Style
from Levenshtein import distance
import hashlib

print(Fore.MAGENTA, "Programm developed by Red_wolf2467")
print(Fore.MAGENTA, "Starting up chatfilter server...")
print(Fore.RESET, "")
server = Quart(__name__)
logger = reds_simple_logger.Logger() #
logger = reds_simple_logger.Logger()
logger.info("Server init complete! Continuing startup...")


Expand All @@ -26,6 +27,11 @@ def load_ids():
return json.load(ids_list)


def load_keys():
with open("key_hash.json", "r", encoding="utf-8") as key_hash_list:
return json.load(key_hash_list)


logger.working("Loading badwords.json...")
try:
badwords = load_badwords()
Expand All @@ -50,6 +56,14 @@ def load_ids():
logger.error("Failed to load ids.json\n" + str(e))
sys.exit(0)

logger.working("Loading key_hash.json...")
try:
key_hash_list = load_keys()
logger.success("Loaded key_hash.json")
except Exception as e:
logger.error("Failed to load key_hash.json\n" + str(e))
sys.exit(0)


def check_chatfilter(input_str: str, badwords, goodwords):
threshold: int = 1 if len(input_str) < 50 else 2
Expand Down Expand Up @@ -98,10 +112,19 @@ def check_user_db(input_id: int, ids_list):
return rt_data



def hash_string(string: str):
hashed = hashlib.sha256(string.encode()).hexdigest()
return hashed


@server.route("/chatfilter")
async def check_message():
data = await request.get_json()


if hash_string(data["key"]) in ha

message = data["message"]
results = check_chatfilter(message, badwords, goodwords)

Expand Down

0 comments on commit 0da2749

Please sign in to comment.