You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/docs/tutorial/security/oauth2-jwt.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,20 +64,20 @@ If your database is stolen, the thief won't have your users' plaintext passwords
64
64
65
65
So, the thief won't be able to try to use that password in another system (as many users use the same password everywhere, this would be dangerous).
66
66
67
-
## Install `passlib` { #install-passlib }
67
+
## Install `pwdlib` { #install-pwdlib }
68
68
69
-
PassLib is a great Python package to handle password hashes.
69
+
pwdlib is a great Python package to handle password hashes.
70
70
71
71
It supports many secure hashing algorithms and utilities to work with them.
72
72
73
-
The recommended algorithm is "Bcrypt".
73
+
The recommended algorithm is "Argon2".
74
74
75
-
Make sure you create a [virtual environment](../../virtual-environments.md){.internal-link target=_blank}, activate it, and then install PassLib with Bcrypt:
75
+
Make sure you create a [virtual environment](../../virtual-environments.md){.internal-link target=_blank}, activate it, and then install pwdlib with Argon2:
76
76
77
77
<divclass="termy">
78
78
79
79
```console
80
-
$ pip install "passlib[bcrypt]"
80
+
$ pip install "pwdlib[argon2]"
81
81
82
82
---> 100%
83
83
```
@@ -86,7 +86,7 @@ $ pip install "passlib[bcrypt]"
86
86
87
87
/// tip
88
88
89
-
With `passlib`, you could even configure it to be able to read passwords created by **Django**, a **Flask** security plug-in or many others.
89
+
With `pwdlib`, you could even configure it to be able to read passwords created by **Django**, a **Flask** security plug-in or many others.
90
90
91
91
So, you would be able to, for example, share the same data from a Django application in a database with a FastAPI application. Or gradually migrate a Django application using the same database.
92
92
@@ -96,15 +96,15 @@ And your users would be able to login from your Django app or from your **FastAP
96
96
97
97
## Hash and verify the passwords { #hash-and-verify-the-passwords }
98
98
99
-
Import the tools we need from `passlib`.
99
+
Import the tools we need from `pwdlib`.
100
100
101
-
Create a PassLib "context". This is what will be used to hash and verify passwords.
101
+
Create a PasswordHash instance with recommended settings - it will be used for hashing and verifying passwords.
102
102
103
103
/// tip
104
104
105
-
The PassLib context also has functionality to use different hashing algorithms, including deprecated old ones only to allow verifying them, etc.
105
+
pwdlib also supports the bcrypt hashing algorithm but does not include legacy algorithms - for working with outdated hashes, it is recommended to use the passlib library.
106
106
107
-
For example, you could use it to read and verify passwords generated by another system (like Django) but hash any new passwords with a different algorithm like Bcrypt.
107
+
For example, you could use it to read and verify passwords generated by another system (like Django) but hash any new passwords with a different algorithm like Argon2 or Bcrypt.
108
108
109
109
And be compatible with all of them at the same time.
110
110
@@ -120,7 +120,7 @@ And another one to authenticate and return a user.
120
120
121
121
/// note
122
122
123
-
If you check the new (fake) database `fake_users_db`, you will see how the hashed password looks like now: `"$2b$12$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW"`.
123
+
If you check the new (fake) database `fake_users_db`, you will see how the hashed password looks like now: `"$argon2id$v=19$m=65536,t=3,p=4$wagCPXjifgvUFBzq4hqe3w$CYaIb8sB+wtD+Vu/P4uod1+Qof8h+1g7bbDlBID48Rc"`.
124
124
125
125
///
126
126
@@ -264,7 +264,7 @@ Many packages that simplify it a lot have to make many compromises with the data
264
264
265
265
It gives you all the flexibility to choose the ones that fit your project the best.
266
266
267
-
And you can use directly many well maintained and widely used packages like `passlib` and `PyJWT`, because **FastAPI** doesn't require any complex mechanisms to integrate external packages.
267
+
And you can use directly many well maintained and widely used packages like `pwdlib` and `PyJWT`, because **FastAPI** doesn't require any complex mechanisms to integrate external packages.
268
268
269
269
But it provides you the tools to simplify the process as much as possible without compromising flexibility, robustness, or security.
0 commit comments