mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Added Simple Hash backend for use with external tools
This commit is contained in:
24
sso/backends.py
Normal file
24
sso/backends.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from django.contrib.auth.backends import ModelBackend
|
||||
from django.contrib.auth.models import User
|
||||
from hashlib import sha1
|
||||
|
||||
|
||||
class SimpleHashModelBackend(ModelBackend):
|
||||
|
||||
def authenticate(self, username=None, password=None):
|
||||
try:
|
||||
user = User.objects.get(username=username)
|
||||
except User.DoesNotExist:
|
||||
return None
|
||||
|
||||
if '$' in user.password:
|
||||
if user.check_password(password)
|
||||
user.password = sha1(password).hexdigest()
|
||||
user.save()
|
||||
return user
|
||||
else:
|
||||
if user.password == sha1(password).hexdigest():
|
||||
return user
|
||||
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user