Escriu per cercar…

Security

FastAPI provides several tools to help you deal with Security easily, rapidly, in a standard way, without having to study and learn all the security specifications.

Aquesta pàgina encara no s'ha traduït — es mostra en l'idioma original:English

Introducció

Hash password

Argon2 is a modern, secure password hashing algorithm and winner of the 2015 Password Hashing Competition. It’s memory-hard and resists brute-force, side-channel, and precomputation attacks, making it the top choice for securing passwords in modern systems.

ps
uv add argon2-cffi
python
from argon2 import PasswordHasher
ph = PasswordHasher()
res = ph.hash("MySecurePassword")
print(res)

To check whether a user-entered password matches the stored hash:

python
from argon2 import PasswordHasher
ph = PasswordHasher()
res = ph.hash("MySecurePassword")
try:
    ph.verify(res, "MySecurePassword")
    print("Password match!")
except Exception:
    print("Incorrect password.")

Bearer authentication

Bearer authentication (also called token authentication) is an HTTP authentication scheme that involves security tokens called bearer tokens. The name “Bearer authentication” can be understood as “give access to the bearer of this token.” The bearer token is a cryptic string, usually generated by the server in response to a login request. The client must send this token in the Authorization header when making requests to protected resources:

Authorization: Bearer <token>

Estàs llegint una vista prèvia.

Inicia sessió amb Google per llegir la pàgina completa. Un compte de Google inclou 5 pàgines gratuïtes en total; l'alumnat i el professorat llegeixen les pàgines del seu curs sense límit.

Inicia sessió