diff --git a/lib/sukaato/custom_validators.ex b/lib/sukaato/custom_validators.ex index 63792cb..541c5e3 100644 --- a/lib/sukaato/custom_validators.ex +++ b/lib/sukaato/custom_validators.ex @@ -1,6 +1,7 @@ defmodule Sukaato.CustomValidators do import Ecto.Changeset import Validate + import Argon2 @moduledoc """ Provide a collecton of custom validation functions for Ecto database @@ -24,4 +25,12 @@ defmodule Sukaato.CustomValidators do add_error(changeset, field, "is not a valid map") end end + + def encrypt_password(changeset, field \\ :password) when is_atom(field) do + field_value = get_field(changeset, field) + field_value = hash_pwd_salt(field_value) + + put_change(changeset, field, field_value) + changeset + end end