-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |