Implement the basic for a password hashing api
This commit is contained in:
commit
2cc78f2838
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.venv/
|
||||||
|
__pycache__/
|
||||||
|
.ropeproject/
|
25
main.py
Normal file
25
main.py
Normal 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
0
requirements.txt
Normal file
Loading…
Reference in New Issue
Block a user