Перевести пароли на Argon2id и читать секреты через AppRole.
Лимит входа общий для реплик, размер тела ограничен, исходящие клиенты проверяют TLS, если задан CA. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+21
-1
@@ -1,7 +1,20 @@
|
||||
import os
|
||||
|
||||
from argon2 import PasswordHasher
|
||||
from argon2.exceptions import InvalidHashError, VerifyMismatchError
|
||||
|
||||
hasher = PasswordHasher(time_cost=2, memory_cost=8192, parallelism=1)
|
||||
# 19 MiB is the lab floor. Salt and parameters live inside the PHC string.
|
||||
MEMORY_KIB = int(os.environ.get("ARGON2_MEMORY_KIB") or "19456")
|
||||
ITERATIONS = int(os.environ.get("ARGON2_ITERATIONS") or "2")
|
||||
PARALLELISM = int(os.environ.get("ARGON2_PARALLELISM") or "1")
|
||||
|
||||
hasher = PasswordHasher(
|
||||
time_cost=ITERATIONS,
|
||||
memory_cost=MEMORY_KIB,
|
||||
parallelism=PARALLELISM,
|
||||
hash_len=32,
|
||||
salt_len=16,
|
||||
)
|
||||
_dummy = None
|
||||
|
||||
|
||||
@@ -21,3 +34,10 @@ def verify_password(password_hash: str, password: str) -> bool:
|
||||
return hasher.verify(password_hash, password)
|
||||
except (VerifyMismatchError, InvalidHashError, TypeError, ValueError):
|
||||
return False
|
||||
|
||||
|
||||
def needs_rehash(password_hash: str) -> bool:
|
||||
try:
|
||||
return hasher.check_needs_rehash(password_hash)
|
||||
except (InvalidHashError, TypeError, ValueError):
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user