File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed
Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change 11import base64
22import binascii
3+ from hashlib import sha256
4+ from secrets import compare_digest
35from typing import Awaitable , Callable , Iterable
46
57from typing_extensions import NoReturn
@@ -19,7 +21,7 @@ def __init__(
1921 white_paths : Iterable [str ] = (),
2022 ) -> None :
2123 self ._username = username
22- self ._password = password
24+ self ._password_hash = sha256 ( password . encode ( "utf-8" )). digest ()
2325 self ._realm = realm
2426 self ._white_paths = set (white_paths )
2527
@@ -58,7 +60,9 @@ async def middleware(
5860
5961 username , password = credentials
6062
61- if username != self ._username or password != self ._password :
63+ if username != self ._username or not compare_digest (
64+ sha256 (password .encode ("utf-8" )).digest (), self ._password_hash
65+ ):
6266 return await self .raise_error (request )
6367
6468 return await handler (request )
You can’t perform that action at this time.
0 commit comments