New Ory Agent Security is now live! Claim your complimentary test drive. Get Started!

Skip to main content

Argon2 password hashing parameters

Ory Kratos supports password hashing using Argon2 in the Argon2id variant. It's important to set up it's parameters to ensure a stable and reliable operation of Ory Kratos. In essence, you want to fulfill the following constrains:

  1. Duration: the execution time of one hashing operation - this translates to the response time of Ory Kratos on login and registration.
  2. Memory: the amount of available memory on the server
  3. Space: the amount of space for persistent storage

We recommend choosing a duration of 0.5s to 1s and as much memory as possible. To determine the exact recommended values following security best practices, run the CLI helper included in Ory Kratos:

kratos hashers argon2 calibrate 1s

It will output the exact values to use in the configuration.

Head to our blogpost about Argon2 parameters to learn how this command and password checking in Ory Kratos works.

Memory limit for password hashing​

Ory Kratos can limit the memory that memory-hard password hashing uses at once in one process. The limit applies to Argon2 hashing and to verifying imported Argon2, scrypt, and Firebase scrypt hashes. It doesn't apply to bcrypt or PBKDF2.

The limit is off by default. To turn it on, set hashers.memory_limit:

hashers:
memory_limit: 1GiB
argon2:
memory: 128MB

With these values, Ory Kratos runs up to eight Argon2 operations at the same time. An operation that doesn't fit waits up to 5 seconds for memory. If no memory becomes available, the request fails with a 429 Too Many Requests error and the client can retry.

  • A hash that needs more memory than the limit isn't rejected. It runs once no other memory-hard operation is running.
  • To serve more concurrent password logins, increase memory_limit and the memory available to Ory Kratos.
  • To turn the limit off, remove memory_limit or set it to 0B.

Metrics​

Ory Kratos exposes these Prometheus metrics for the limit:

MetricDescription
kratos_hash_memory_reserved_bytesMemory in use by password hashing.
kratos_hash_memory_wait_secondsTime operations waited for memory.
kratos_hash_memory_rejections_totalOperations that failed because no memory was free.

If you encounter any problems like timeouts or out-of-memory errors, consolidate our troubleshooting guide.