View Source ExPassword.Argon2 (expassword_argon2 v0.2.2)

This module implements the ExPassword.Algorithm behaviour to add support for Argon2 hashing algorithms.

Except for specific details about proper options and deeper details, you might looking for ExPassword's documentation.

Summary

Functions

Extracts informations from a given argon2 hash (the options used to generate it in the first place)

Computes the hash for password. A salt of 16 bytes is randomly generated and prepended to password before hashing.

Compares the options used to generate hash to options and returns true if they differ, which means you should rehash the password to update its hash.

Returns true if hash seems to be an Argon2 hash.

Checks that a password matches the given argon2 hash

Functions

get_options(hash)

Extracts informations from a given argon2 hash (the options used to generate it in the first place)

Returns {:error, :invalid} if hash is not a valid argon2 hash else {:ok, map} where map is a Map which contains all the parameters that permitted to compute this hash.

iex> ExPassword.Argon2.get_options("$argon2i$v=19$m=65536,t=4,p=2$<truncated>")
{:ok, %{memory_cost: 65536, threads: 2, time_cost: 4, type: :argon2i, version: 19}}

hash(password, options)

Computes the hash for password. A salt of 16 bytes is randomly generated and prepended to password before hashing.

Valid options are:

  • threads (also called parallelism): number of threads to use for computing the Argon2 hash
  • time_cost (in seconds): maximum amount of time it may take to compute the Argon2 hash
  • memory_cost (in kibibytes): maximum amount of memory that may be used to compute the Argon2 hash
  • type:
    • :argon2i: use the Argon2i hashing algorithm
    • :argon2id (default and recommended): use the Argon2id hashing algorithm

An ArgumentError will be raised if one of the options above is invalid or if an internal error occurs.

needs_rehash?(hash, options)

Compares the options used to generate hash to options and returns true if they differ, which means you should rehash the password to update its hash.

valid?(hash)

Returns true if hash seems to be an Argon2 hash.

This function is intended to quickly identify the algorithm which produces the given hash. It does not perform extended checks like get_options/1 nor needs_rehash?/2 nor verify?/2 do.

verify?(password, hash)

Checks that a password matches the given argon2 hash

An ArgumentError will be raised if the hash is somehow invalid or if an internal error occurs.