1
0
mirror of https://github.com/danbee/chess synced 2025-03-04 08:39:06 +00:00

More idiomatic password hashing

This commit is contained in:
Daniel Barber 2018-02-02 14:37:45 -05:00
parent 0568b69cbb
commit 19037c723f
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8

View File

@ -23,11 +23,13 @@ defmodule Chess.Auth.User do
|> hash_password()
end
defp hash_password(
%Ecto.Changeset{valid?: true, changes: %{password: password}} = changeset
) do
change(changeset, Argon2.add_hash(password))
defp hash_password(changeset) do
password = get_change(changeset, :password)
if password do
changeset
|> change(Argon2.add_hash(password))
else
changeset
end
end
defp hash_password(changeset), do: changeset
end