Reputation: 13908
I'm using version 5.1.2 of Comeonin
to hash passwords. The documentation says that either bcrypt_elixir or argon2 are compatible hashing libraries. The problem I'm encountering happens with both.
If I try to use Argon2.hash_pwd_salt
as recommended by the docs, I get the following error:
** (UndefinedFunctionError) function Comeonin.Argon2.hash_pwd_salt/1 is undefined or private. Did you mean one of:
* hashpwsalt/1
* hashpwsalt/2
BUT, if I follow the error and use Argon2.hashpwsalt/1
I get:
** (ArgumentError) Comeonin.Argon2.hashpwsalt has been removed.
use Argon2.hash_pwd_salt instead.
This same set of errors occurs with bcrypt_elixir. How do I use this library correctly?
For reference, this is my Mix file:
defp deps do
[
{:phoenix, "~> 1.4.7"},
{:phoenix_pubsub, "~> 1.1"},
{:phoenix_ecto, "~> 4.0"},
{:ecto_sql, "~> 3.0"},
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 2.11"},
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:gettext, "~> 0.11"},
{:jason, "~> 1.0"},
{:plug_cowboy, "~> 2.0"},
{:guardian, "~> 1.2.1"},
{:comeonin, "~> 5.1.2"},
{:argon2_elixir, "~> 2.0"},
{:ex_machina, "~> 2.3", only: :test},
{:faker, "~> 0.12", only: :test}
]
end
Upvotes: 1
Views: 1017
Reputation: 444
Because Function Comeonin.Argon2.hashpwsalt is removed from Comeonin 5.x.x. So you got the error:
** (ArgumentError) Comeonin.Argon2.hashpwsalt has been removed.
use Argon2.hash_pwd_salt instead.
In version 5.0 and above, Comeonin now provides two behaviours, Comeonin and Comeonin.PasswordHash, which password hash libraries then implement.
With these changes, Comeonin is now a dependency of the password hashing library you choose to use, and in most cases, you will not use it directly.
Argon2 has already implemented the Comeonin and Comeonin.PasswordHash behaviours so you can remove {:comeonin, "~> 5.1"} from mix.exs and use only {:argon2_elixir, "~> 2.0"}
Correct the function Comeonin.Argon2.hash_pwd_salt to Argon2.hash_pwd_salt to fix this error:
** (UndefinedFunctionError) function Comeonin.Argon2.hash_pwd_salt/1 is undefined or private. Did you mean one of:
* hashpwsalt/1
* hashpwsalt/2
Upvotes: 0
Reputation: 48599
I can call:
Argon2.hash_pwd_salt(password)
with no error in my app. And, to verify a password:
Argon2.verify_pass(plain_text_password, user.password)
Here's my mix.exs:
{:guardian, "~> 1.2"},
{:comeonin, "~> 5.1"},
{:argon2_elixir, "~> 2.0"}
Are you sure you did:
$ mix deps.get
?? Could you post the output to prove it? But then again, I can't duplicate your error when I do:
mix deps.clean argon2_elixir
I get the error:
warning: function Argon2.hash_pwd_salt/1 is undefined (module Argon2 is not available)
About this error message:
(UndefinedFunctionError) function Comeonin.Argon2.hash_pwd_salt/1 is
Are you literally writing:
Comeonin.Argon2.hash_pwd_salt(password)
in your code?? Yep! I can duplicate your error if I write that.
The module name Comeonin
doesn't appear anywhere in my code, which means that the implementation of the Argon2
functions must employ comeonin
functions. Let's take a look at the Argon2 source code...when I peruse the elixir code in myapp/deps/argon2_elixir/lib/argon2.ex
, I see:
use Comeonin
And, if you know anything about elixir macros, you know that use
is a magic line that injects an indeterminable number of modules, functions, and occasionally variables into the code at the point of the use statement.
By the way, the comeonin
docs on hashing passwords say:
...most developers will find the
Argon2.add_hash
andArgon2.check_pass
convenience functions more useful [than the ones I listed above], especially when working on a Phoenix app with Ecto.
Upvotes: 3