Use - as hash delimiter instead
This commit is contained in:
@@ -234,7 +234,8 @@ def _hash_password(pw: str) -> str:
|
|||||||
salt = os.urandom(16)
|
salt = os.urandom(16)
|
||||||
iterations = 200_000
|
iterations = 200_000
|
||||||
dk = hashlib.pbkdf2_hmac('sha256', pw.encode('utf-8'), salt, iterations)
|
dk = hashlib.pbkdf2_hmac('sha256', pw.encode('utf-8'), salt, iterations)
|
||||||
return f"pbkdf2_sha256${iterations}${binascii.hexlify(salt).decode()}${binascii.hexlify(dk).decode()}"
|
# use - as the delimiter to avoid Docker env variable substitution
|
||||||
|
return f"pbkdf2_sha256-{iterations}-{binascii.hexlify(salt).decode()}-{binascii.hexlify(dk).decode()}"
|
||||||
except Exception:
|
except Exception:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@@ -243,7 +244,7 @@ def _verify_password(stored: str, pw: Optional[str]) -> bool:
|
|||||||
if not pw or not stored:
|
if not pw or not stored:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
algo, iter_s, salt_hex, hash_hex = stored.split("$")
|
algo, iter_s, salt_hex, hash_hex = stored.split("-")
|
||||||
if algo != 'pbkdf2_sha256':
|
if algo != 'pbkdf2_sha256':
|
||||||
return False
|
return False
|
||||||
iterations = int(iter_s)
|
iterations = int(iter_s)
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ def _hash_password(pw: str) -> str:
|
|||||||
salt = os.urandom(16)
|
salt = os.urandom(16)
|
||||||
iterations = 200_000
|
iterations = 200_000
|
||||||
dk = hashlib.pbkdf2_hmac('sha256', pw.encode('utf-8'), salt, iterations)
|
dk = hashlib.pbkdf2_hmac('sha256', pw.encode('utf-8'), salt, iterations)
|
||||||
return f"pbkdf2_sha256${iterations}${binascii.hexlify(salt).decode()}${binascii.hexlify(dk).decode()}"
|
# use - as the delimiter to avoid Docker env variable substitution
|
||||||
|
return f"pbkdf2_sha256-{iterations}-{binascii.hexlify(salt).decode()}-{binascii.hexlify(dk).decode()}"
|
||||||
except Exception:
|
except Exception:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user