openstreetmap-ng
openstreetmap-ng copied to clipboard
Prehash login passwords on client-side before sending them
This will introduce a new safeguard against potentially compromised server. By having strong client-side hashing step, we could reduce server-side hash complexity and save on resources.
@staticmethod
def client_prehash(password: PasswordStr) -> str:
"""
Prehash a password using the client's algorithm.
"""
return pbkdf2_hmac(
hash_name='sha256',
password=password.get_secret_value().encode(),
salt=b'',
iterations=20_000,
).hex()
https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#browser_compatibility https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/deriveBits#browser_compatibility