When I was 15, I was completely obsessed with coding, and back then I thought an authentication system required a thousand lines of code.
I don’t know if everyone is like this, but I tend to imagine anything that seems mysterious as extremely complex and difficult, pushing myself back before I even start.
But after three years in backend development and a year in cybersecurity, I realized—why was it actually so simple?
This is a sample code for authentication using FastAPI.
from fastapi import FastAPI
import bcrypt
app=FastAPI()
#Call the known database user_info_user_data to retrieve the user hash
@app.get("/data/{data_user}")
def user_data(data_user:str):
#Assume the database function is user_info_user_data
user_info=user_info_user_data(data_user)
return {"user_info":user_info}
#→ Verify the password hash
#Assume the user input function is user_input_
def hash_(user_input,user_data):
user_input=user_input
user_data=user_data()
return bcrypt.checkpw(user_input.encode('utf-8'), user_data)
It’s obvious that I cut corners in this sample code.
You can tell my personality from this: I’m extremely prone to procrastination and really like to avoid things.
The truth is, this blog post should have been published three days ago, but I only finished writing and posting it today.
Ok, enough chatter—let’s return to the core of our blog post: authentication.
Top comments (0)