Proper exception handling

This commit is contained in:
florian committed 2026-10-29 11:24:38 +01:00
1 parent 0cf6bae59d
commit bfe49e40ed
1 file changed
+2 -1
+2 -1
View File
@@ -1,4 +1,5 @@
from argon2 import PasswordHasher from argon2 import PasswordHasher
from argon2.exceptions import InvalidHashError, VerifyMismatchError
ph = PasswordHasher() ph = PasswordHasher()
@@ -8,7 +9,7 @@ def hash_api_key(api_key: str) -> str:
def verify_api_key(api_key: str, hashed: str) -> bool: def verify_api_key(api_key: str, hashed: str) -> bool:
try: try:
return ph.verify(hashed, api_key) return ph.verify(hashed, api_key)
except Exception: except (VerifyMismatchError, InvalidHashError):
return False return False
if __name__=="__main__": if __name__=="__main__":