Hi,
I am using Cloak.Ecto to encrypt username and email, and hash the user password(user_password_hash).
In the changeset, I pipe the cs to validate_length(:user_password, min: 8)
and then to validate_password (a private function).
Curiously, the validate_password triggers an invalid credentials message, but, the validate_length (which is before in the pipeline), does not trigger an error when supplied with less than 8 characters.
I don’t know if this is because Cloak.Ecto has anything to do with it.
Part of my schema:
Encrypted fields
field :user_email, Circles.EncryptedBinary
field :user_email_hash, Cloak.Ecto.SHA256
field :user_name, Circles.EncryptedBinary
field :user_password_hash, Cloak.Ecto.SHA256
@required_fields ~w(user_name user_email user_password)a
@mail_regex ~r/^[A-Za-z0-9._%±]+@[A-Za-z0-9.-]+.[A-Za-z]+$/
def registration_changeset(%Aiuser{} = aiuser, attrs \ %{}) do
aiuser
|> Map.merge(attrs)
|> cast(attrs, @required_fields)
|> validate_required(@required_fields)
|> validate_email()
|> validate_length(:user_password, min: 8)
|> put_hashed_fields()
|> new_user_id()
|> unique_constraint(:user_email_hash, name: :aiuser_user_email_hash_index)
|> unique_constraint(:user_id, name: :aiuser_pkey)
end
@required_for_login ~w[user_email user_password]a
def login_changeset(%Aiuser{} = aiuser, attrs \ %{}) do
aiuser
|> Map.merge(attrs)
|> cast(attrs, @required_for_login)
|> validate_required(@required_for_login)
|> validate_email()
|> validate_length(:user_password, min: 8)
|> put_hashed_fields()
|> validate_password()
end
Erlang/OTP 23 [erts-11.0.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]
Elixir 1.11.3 (compiled with Erlang/OTP 23)
phoenix 1.5.7
cloak 1.0.3
cloak_ecto 1.1.1
Thanks for any ideas.
Gusti.