Packages
argon2_elixir
0.10.1
4.1.3
4.1.2
4.1.1
4.1.0
4.0.0
3.2.1
3.2.0
3.1.0
3.0.0
2.4.1
2.4.0
2.3.0
2.2.1
2.2.0
2.1.2
2.1.1
2.1.0
2.0.5
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0
1.3.3
1.3.1
1.3.0
1.2.14
1.2.13
1.2.12
1.2.11
1.2.10
1.2.9
1.2.8
1.2.7
1.2.6
1.2.5
1.2.4
1.2.2
1.2.1
1.2.0
1.1.0
1.0.0
0.12.0
0.11.4
0.11.3
0.11.2
0.11.0
0.10.1
0.10.0
0.9.1
0.9.0
0.8.0
Argon2 password hashing algorithm for Elixir
Current section
Files
Jump to
Current section
Files
lib/argon2/utils.ex
defmodule Argon2.Utils do
@moduledoc """
Tools to be used with Argon2.
"""
alias Argon2.Base
@doc """
Hash a password with Argon2 and print out a report.
"""
def report(password, salt, opts \\ []) do
{exec_time, result} = :timer.tc(Base, :hash_password, [password, salt, opts ++ [format: :report]])
{raw, encoded, {t, m, p, _, _, _, argon2_type}} = result
Argon2.verify_hash(encoded, password, argon2_type: argon2_type)
|> format_result(argon2_type, t, m, p, raw, encoded, exec_time)
end
defp format_result(check, argon2_type, t, m, p, raw, encoded, exec_time) do
IO.puts """
Type:\t\t#{format_type(argon2_type)}
Iterations:\t#{t}
Memory:\t\t#{trunc(:math.pow(2, m - 10))} MiB
Parallelism:\t#{p}
Hash:\t\t#{raw}
Encoded:\t#{encoded}
#{format_time(exec_time)} seconds
Verification #{if check, do: "ok", else: "failed"}
"""
end
defp format_type(0), do: "Argon2d"
defp format_type(1), do: "Argon2i"
defp format_type(2), do: "Argon2id"
defp format_time(time) do
Float.round(time / 1_000_000, 2)
end
end