Added changeset encyption function for password field
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user