riverrun / argon2_elixir

Elixir wrapper for the Argon2 password hashing algorithm
Apache License 2.0
229 stars 34 forks source link

Upgrading from v1.2.9 to v1.2.12 breaks `hashpwsalt` under some circumstanctes #15

Closed rohit-lshift closed 7 years ago

rohit-lshift commented 7 years ago

Firstly thanks for the lib. It's great along with your other open source work.

I just upgraded this library to v1.2.12 and Comeonin.Argon2.hashpwsalt function under some circumstances is returning values like {<<184>>, "$argon2i$v=19$m=256,t=1,p=1$iabL0itQRUH/Ock+gk6dmQ$OmqPbEWpE+ay6WIeW9LxCtym2ue29UAgVKKWIqbk2+s", {1, 8, 1, 0, true, 32, 1} instead of a string.

But when I run the same function with the same input in a repl session, I get back a string.

This behaviour is obviously very strange. Any help on this would be appreciated.

Thanks

riverrun commented 7 years ago

What is the command when you get this strange output? Is it in your tests?

rohit-lshift commented 7 years ago

It is in the tests. I ran my tests to see if everything is ok but some of my tests started failing.

This bit of my code started throwing an exception:

defp generate_encrypted_password(%{valid?: true, changes: %{password: password}} = current_changeset) do
  put_change(current_changeset, :password_hash, Comeonin.Argon2.hashpwsalt(password))
end

Exact error:

** (Ecto.ChangeError) value `{<<184>>, "$argon2i$v=19$m=256,t=1,p=1$BRw8jSyk92FpGyIFZbaGFQ$wecOF+3jV3HaPZqSEcamxDn9FcXlfTLQzgFclt+/JuI", {1, 8, 1, 0, true, 32, 1}}` for `Enki.Accounts.User.password_hash` in `insert` does not match type :string
stacktrace:
  (ecto) lib/ecto/repo/schema.ex:788: Ecto.Repo.Schema.dump_field!/6
  (ecto) lib/ecto/repo/schema.ex:797: anonymous fn/6 in Ecto.Repo.Schema.dump_fields!/5
  (stdlib) lists.erl:1263: :lists.foldl/3
  (ecto) lib/ecto/repo/schema.ex:795: Ecto.Repo.Schema.dump_fields!/5
  (ecto) lib/ecto/repo/schema.ex:744: Ecto.Repo.Schema.dump_changes!/6
  (ecto) lib/ecto/repo/schema.ex:207: anonymous fn/14 in Ecto.Repo.Schema.do_insert/4
riverrun commented 7 years ago

Ok. I'll have a fix soon.

rohit-lshift commented 7 years ago

Cheers!

riverrun commented 7 years ago

1.2.13 has a fix - I hope :)

rohit-lshift commented 7 years ago

Its fixed. Thanks!