26 lines
726 B
Python
26 lines
726 B
Python
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}
|