AshAuthentication.Argon2Provider (ash_authentication v4.9.5)

View Source

Provides an implementation of AshAuthentication.HashProvider using Argon2.

Summary

Functions

Given some user input as a string, convert it into it's hashed form using Argon2.

Simulate a password check to help avoid timing attacks.

Check if the user input matches the hash.

Functions

hash(input)

@spec hash(String.t()) :: {:ok, String.t()} | :error

Given some user input as a string, convert it into it's hashed form using Argon2.

Example

iex> {:ok, hashed} = hash("Marty McFly")
...> String.starts_with?(hashed, "$argon2id$")
true

simulate()

@spec simulate() :: false

Simulate a password check to help avoid timing attacks.

Example

iex> simulate()
false

valid?(input, hash)

@spec valid?(input :: String.t() | nil, hash :: String.t()) :: boolean()

Check if the user input matches the hash.

Example

iex> valid?("Marty McFly", "$argon2id$v=19$m=256,t=1,p=2$T9zYADIg2xF5P21FgyIX5g$5K1vy8VTMlEZUWuO8HPOJcu239FkHen5XKmg7uviHEk")
true