Packages
argon2_elixir
0.10.0
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 """
Various tools.
"""
alias Argon2.Base
@doc """
Hash a password with Argon2 and print out a report.
"""
def report(password, salt, opts \\ []) do
{t, m, p, _, _, hashlen, argon2_type} = Base.get_opts(opts)
encodedlen = Base.encodedlen_nif(t, m, p, byte_size(salt), hashlen, argon2_type)
{exec_time, {raw, encoded}} = :timer.tc(Base, :hash_nif,
[t, m, p, password, salt, 1, hashlen, encodedlen, argon2_type, 0])
Base.verify_nif(encoded, password, 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#{m}
Parallelism:\t#{p}
Hash:\t\t#{:binary.list_to_bin(raw)}
Encoded:\t#{:binary.list_to_bin(encoded)}
#{format_time(exec_time)} seconds
Verification #{if check == 0, 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