Hash a password with PBKDF2-SHA256. Returns (hash_hex, salt_hex).
(password: str, salt: bytes = None)
| 190 | |
| 191 | @staticmethod |
| 192 | def _hash_password(password: str, salt: bytes = None) -> tuple: |
| 193 | """Hash a password with PBKDF2-SHA256. Returns (hash_hex, salt_hex).""" |
| 194 | if salt is None: |
| 195 | salt = secrets.token_bytes(32) |
| 196 | pw_hash = hashlib.pbkdf2_hmac( |
| 197 | 'sha256', |
| 198 | password.encode('utf-8'), |
| 199 | salt, |
| 200 | AuthManager.PBKDF2_ITERATIONS |
| 201 | ) |
| 202 | return pw_hash.hex(), salt.hex() |
| 203 | |
| 204 | @staticmethod |
| 205 | def _verify_password(password: str, stored_hash: str, stored_salt: str) -> bool: |
no test coverage detected