Skip to content

Commit

Permalink
wrap argon2 verify with exception catcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf Peschke committed Nov 30, 2023
1 parent 1127dd8 commit 8b5cf1d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions auth/libraries/pip-auth/authlib/hashing_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
import argon2


HASH_WITH_SALT_LENGTH = 152


class HashingHandler:
def hash(self, to_hash: str, hash_reference: Optional[str] = None) -> str:
ph = argon2.PasswordHasher()
return ph.hash(to_hash)

def verify(self, hash: str, password: str) -> bool:
ph = argon2.PasswordHasher()
return ph.verify(hash, password)
try:
return ph.verify(hash, password)
except (
argon2.exceptions.VerifyMismatchError,
argon2.exceptions.VerificationError,
argon2.exceptions.InvalidHashError,
):
return False

0 comments on commit 8b5cf1d

Please sign in to comment.