Plain is headed towards 1.0! Subscribe for development updates →

plain.password

Password authentication for Plain.

Usage

To enable password authentication in your Plain application, add the PasswordLoginView to your urls.py:

# app/urls.py
from plain.urls import path
from plain.passwords.views import PasswordLoginView

urlpatterns = [
    path('login/', PasswordLoginView.as_view(), name='login'),
    # ...
]

This sets up a basic login view where users can authenticate using their username and password.

FAQs

How do I customize the login form?

To customize the login form, you can subclass PasswordLoginForm and override its fields or methods as needed. Then, set the form_class attribute in your PasswordLoginView to use your custom form.

# app/forms.py
from plain.passwords.forms import PasswordLoginForm

class MyCustomLoginForm(PasswordLoginForm):
    # Add custom fields or override methods here
    pass
# app/views.py
from plain.passwords.views import PasswordLoginView
from .forms import MyCustomLoginForm

class MyPasswordLoginView(PasswordLoginView):
    form_class = MyCustomLoginForm

Update your urls.py to use your custom view:

# app/urls.py
from plain.urls import path
from .views import MyPasswordLoginView

urlpatterns = [
    path('login/', MyPasswordLoginView.as_view(), name='login'),
    # ...
]
 1# The number of seconds a password reset link is valid for (default: 3 days).
 2PASSWORD_RESET_TIMEOUT: int = 60 * 60 * 24 * 3
 3
 4# the first hasher in this list is the preferred algorithm.  any
 5# password using different algorithms will be converted automatically
 6# upon login
 7PASSWORD_HASHERS: list = [
 8    "plain.passwords.hashers.PBKDF2PasswordHasher",
 9    "plain.passwords.hashers.PBKDF2SHA1PasswordHasher",
10    "plain.passwords.hashers.Argon2PasswordHasher",
11    "plain.passwords.hashers.BCryptSHA256PasswordHasher",
12    "plain.passwords.hashers.ScryptPasswordHasher",
13]