'django login without password
I'm looking for a way how to login without password. During create new user I noticed that, password field has default value empty, but not null. How can I do login with empty password? Because not all user need to have password set.
models.py
class user(AbstractUser):
database:
| username | password |
| -------- | -------------- |
| A | |
| B | 123 |
views.py
user = authenticate(request, username='A', password='')
if user is not None:
login(request, user)
return redirect('index')
Solution 1:[1]
Derive a custom authentication backend from the default backend (django.contrib.auth.backends.ModelBackend) that allows authentication without a password for the users that are eligible for it, and set AUTHENTICATION_BACKENDS to point to that class.
Then your views, or whatever calls authenticate(), will work out of the box.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | AKX |
