File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2323"""Utilities dealing with encryption and randomness."""
2424
2525import binascii
26+ import hmac
2627import random
2728from string import ascii_lowercase
2829
@@ -190,15 +191,15 @@ def validate_password(authentication: str, password: str) -> bool:
190191
191192 """
192193 method , payload = parse_authentication (authentication )
194+ password_bytes = password .encode ("utf-8" )
195+ payload_bytes = payload .encode ("utf-8" )
193196 if method == "bcrypt" :
194- password_bytes = password .encode ("utf-8" )
195- payload_bytes = payload .encode ("utf-8" )
196197 try :
197- return bcrypt .hashpw (password_bytes , payload_bytes ) == payload_bytes
198+ return bcrypt .checkpw (password_bytes , payload_bytes )
198199 except ValueError :
199200 return False
200201 elif method == "plaintext" :
201- return payload == password
202+ return hmac . compare_digest ( password_bytes , payload_bytes )
202203 else :
203204 raise ValueError ("Authentication method not known." )
204205
You can’t perform that action at this time.
0 commit comments