Skip to content

Commit 7d2d28a

Browse files
refactor: Inline password hash comparison in serializers
Simplifies the conditional check by removing temporary variables for the token hash and user password hash.
1 parent 670baff commit 7d2d28a

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

rest_framework_simplejwt/serializers.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,7 @@ def validate(self, attrs: dict[str, Any]) -> dict[str, str]:
131131
)
132132

133133
if api_settings.CHECK_REVOKE_TOKEN:
134-
token_hash = refresh.payload.get(api_settings.REVOKE_TOKEN_CLAIM)
135-
user_hash = get_md5_hash_password(user.password)
136-
137-
if token_hash != user_hash:
134+
if refresh.payload.get(api_settings.REVOKE_TOKEN_CLAIM) != get_md5_hash_password(user.password):
138135
# If the password has changed, we blacklist the token
139136
# to prevent any further use.
140137
if (
@@ -201,10 +198,7 @@ def validate(self, attrs: dict[str, Any]) -> dict[str, str]:
201198
)
202199

203200
if api_settings.CHECK_REVOKE_TOKEN:
204-
token_hash = token.payload.get(api_settings.REVOKE_TOKEN_CLAIM)
205-
user_hash = get_md5_hash_password(user.password)
206-
207-
if token_hash != user_hash:
201+
if token.payload.get(api_settings.REVOKE_TOKEN_CLAIM) != get_md5_hash_password(user.password):
208202
# If the password has changed, we blacklist the token
209203
# to prevent any further use.
210204
if (

0 commit comments

Comments
 (0)