Skip to content

Commit 435511d

Browse files
committed
Expand/reorganize documentation.
This adds a usage guide with a bit more detail than the index/README, and explicitly organizes the documentation sidebar in a more useful way.
1 parent a32d7f6 commit 435511d

File tree

7 files changed

+89
-7
lines changed

7 files changed

+89
-7
lines changed

docs/api.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
.. _api:
44

5-
Using the Pwned Passwords API directly
6-
======================================
5+
Direct Pwned Passwords API access
6+
=================================
77

88
If :ref:`the validator <validator>` and :ref:`middleware <middleware>` do not
99
meet your needs, you can also directly check a password against Pwned

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ Released May 2024
7373

7474
* Supported Django versions are now 4.2 and 5.0.
7575

76+
* Expanded/reorganized documentation.
77+
7678

7779
Releases not under DjangoVer
7880
----------------------------

docs/faq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ for Python 3.10 only, you could run:
144144
145145
By default, ``nox`` will only run the tasks whose associated Python versions
146146
are available on your system. For example, if you have only Python 3.8 and 3.9
147-
installed, test runs for Python 3.7, 3.10, and 3.11 would be skipped.
147+
installed, test runs for Python 3.10, 3.11, and 3.12 would be skipped.
148148

149149

150150
How am I allowed to use this code?

docs/index.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,26 @@ Documentation contents
6060
----------------------
6161

6262
.. toctree::
63+
:caption: Installation and usage
6364
:maxdepth: 1
6465

6566
install
67+
usage
68+
69+
.. toctree::
70+
:caption: API reference
71+
:maxdepth: 1
72+
6673
validator
6774
middleware
6875
api
6976
exceptions
7077
settings
78+
79+
.. toctree::
80+
:caption: Other documentation
81+
:maxdepth: 1
82+
7183
faq
7284
changelog
7385

docs/middleware.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
.. _middleware:
44

55

6-
Using the middleware
7-
====================
6+
The password-checking middleware
7+
================================
88

99
To help with situations where a potentially-compromised password is used
1010
:ref:`in ways Django's password validators won't catch

docs/usage.rst

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
.. _usage:
2+
3+
4+
Usage guide
5+
===========
6+
7+
The recommended configuration is to enable both :ref:`the password validator
8+
<validator>` and :ref:`the automatic password-checking middleware
9+
<middleware>`. To do this, make the following changes to your Django settings.
10+
11+
First, add :ref:`the validator <validator>` to your
12+
:setting:`AUTH_PASSWORD_VALIDATORS` list:
13+
14+
.. code-block:: python
15+
16+
AUTH_PASSWORD_VALIDATORS = [
17+
# ... other password validators ...
18+
{
19+
"NAME": "pwned_passwords_django.validators.PwnedPasswordsValidator",
20+
},
21+
]
22+
23+
This will cause user creation (provided it's done via Django's built-in
24+
:class:`~django.contrib.auth.forms.UserCreationForm` or a subclass, or via
25+
Django's ``createsuperuser`` management command) and password changes (via the
26+
built-in Django password-change views/forms, and the ``changepassword``
27+
management comment) to check the Pwned Passwords database, and reject any
28+
password found there.
29+
30+
Then, add :ref:`the middleware <middleware>` to your :setting:`MIDDLEWARE`
31+
list:
32+
33+
.. code-block:: python
34+
35+
MIDDLEWARE = [
36+
# .. other middlewares ...
37+
"pwned_passwords_django.middleware.pwned_passwords_middleware",
38+
]
39+
40+
This will add the attribute ``pwned_passwords`` to every Django
41+
:class:`~django.http.HttpRequest` object. The value of this attribute will be a
42+
:class:`list` of :class:`str`, where each item in the list is the name of a
43+
field in ``request.POST`` believed to contain a compromised password. If the
44+
request method was not ``POST``, did not appear to contain any passwords, or no
45+
compromised passwords were detected, the ``request.pwned_passwords`` list will
46+
be empty.
47+
48+
49+
Identifying passwords in request payloads
50+
-----------------------------------------
51+
52+
By default, the middleware checks any field in ``request.POST`` whose name is a
53+
case-insensitive match for the regex ``r"PASS"``. This will catch many common
54+
password field names, such as ``"password"``, ``"passphrase"``, and so on. But
55+
if your site uses something significantly different, you will need to configure
56+
``pwned-passwords-django`` to check for it. You can do this by specifying the
57+
Django setting ``PWNED_PASSWORDS`` as a dictionary, and placing a regex -- as a
58+
string, not as a compiled regex object -- in the key ``"PASSWORD_REGEX"`` of
59+
that dictionary. For example, if your site uses a field named ``"token"``
60+
for its passwords, you could specify this in your Django settings:
61+
62+
.. code-block:: python
63+
64+
PWNED_PASSWORDS = {
65+
"PASSWORD_REGEX": r"token",
66+
}
67+
68+
See :ref:`the settings documentation <settings>` for full details.

docs/validator.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
.. _validator:
44

55

6-
Using the password validator
7-
============================
6+
The password validator
7+
======================
88

99
.. class:: PwnedPasswordsValidator
1010

0 commit comments

Comments
 (0)