Behaviour for password hashing implementations.
Sigra uses this behaviour to abstract the password hashing algorithm, allowing transparent migration between hashing algorithms (e.g., bcrypt to Argon2id) and easy testing via Mox.
Default Implementation
Sigra.Hashers.Argon2 -- uses Argon2id, the OWASP-recommended algorithm.
Mox Usage
Mox.defmock(MockHasher, for: Sigra.Hasher)
Summary
Callbacks
Hashes a plaintext password and returns the hashed string.
Runs a dummy hash operation to prevent timing-based user enumeration.
Verifies a plaintext password against a hashed password.
Callbacks
Hashes a plaintext password and returns the hashed string.
@callback no_user_verify() :: :ok
Runs a dummy hash operation to prevent timing-based user enumeration.
This must take approximately the same time as a real hash verification to prevent attackers from distinguishing between "user exists" and "user does not exist" based on response time.
Verifies a plaintext password against a hashed password.