Implement the basic for a password hashing api

This commit is contained in:
Colin Bassett 2025-02-21 11:54:39 -05:00
commit 2cc78f2838
3 changed files with 28 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.venv/
__pycache__/
.ropeproject/

25
main.py Normal file
View File

@ -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}

0
requirements.txt Normal file
View File