commit 2cc78f28387a8014fcbede0ee216f8ac643c0c4e Author: Colin Bassett Date: Fri Feb 21 11:54:39 2025 -0500 Implement the basic for a password hashing api diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d334cc6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.venv/ +__pycache__/ +.ropeproject/ diff --git a/main.py b/main.py new file mode 100644 index 0000000..d2957b3 --- /dev/null +++ b/main.py @@ -0,0 +1,25 @@ +from fastapi import FastAPI +import hashlib +import random + +app = FastAPI() + +@app.get("/") +def hello_world(): + return {"message": "Hello World!"} + +@app.get("/hash/{password}") +def hash(password: str): + salt = random.randint(00000, 99999) + password = password + str(salt) + hashed = hashlib.sha256(password.encode()).hexdigest() + return {"hash": hashed, "salt": salt} + +@app.get("/verify/{password}/{hash}/{salt}") +def verify(password: str, hash: str, salt: int): + password = password + str(salt) + hashed = hashlib.sha256(password.encode()).hexdigest() + if hashed == hash: + return {"message": "Password is correct", "correct": True} + + return {"message": "Password is incorrect", "correct": False} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e69de29