Skip to content

Commit

Permalink
Fix/1/super user auth (#91)
Browse files Browse the repository at this point in the history
* #1 fix : modify super user's password encryption

* #1 fix : super user password verification
  • Loading branch information
0321minji authored Aug 21, 2024
1 parent fcd46e8 commit 96323c5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Cognisle/settings/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@
'django.contrib.auth.hashers.ScryptPasswordHasher',
]

AUTHENTICATION_BACKENDS = [
'users.auth_backends.BcryptSuperuserBackend', # 커스터마이즈된 인증 백엔드
'django.contrib.auth.backends.ModelBackend', # 기본 백엔드
]

# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/

Expand Down
24 changes: 24 additions & 0 deletions users/auth_backends.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# users/auth_backends.py

from django.contrib.auth.backends import BaseBackend
from django.contrib.auth import get_user_model
import bcrypt

User = get_user_model()

class BcryptSuperuserBackend(BaseBackend):
def authenticate(self, request, username=None, password=None, **kwargs):
try:
user = User.objects.get(email=username)
# 비밀번호가 맞는지 bcrypt로 검증
print(password,user.password)
if bcrypt.checkpw(password.encode('utf-8'), user.password.encode('utf-8')):
return user
except User.DoesNotExist:
return None

def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None

0 comments on commit 96323c5

Please sign in to comment.