Added changeset encyption function for password field

This commit is contained in:
Alex Tavarez
2025-09-02 20:23:53 -04:00
parent fe508ec21e
commit 50202e72c6

View File

@@ -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