Password Validator v0.4.0 PasswordValidator View Source
Primary interface to PasswordValidator. The two main methods are validate/3
and validate_password/2
.
Examples
iex> opts = [
...> length: [max: 6],
...> ]
iex> PasswordValidator.validate_password("too_long", opts)
{:error, ["String is too long. 8 but maximum is 6"]}
iex> opts = [
...> length: [min: 5, max: 30],
...> character_set: [
...> lower_case: 1, # at least one lower case letter
...> upper_case: [3, :infinity], # at least three upper case letters
...> numbers: [0, 4], # at most 4 numbers
...> special: [0, 0], # no special characters allowed
...> ]
...> ]
iex> changeset = Ecto.Changeset.change({%{password: "Simple_pass12345"}, %{}}, %{})
iex> changeset = PasswordValidator.validate(changeset, :password, opts)
iex> changeset.errors
[password: {"Too many special (1 but maximum is 0)", []},
password: {"Too many numbers (5 but maximum is 4)", []},
password: {"Not enough upper_case characters (only 1 instead of at least 3)", []}]
Link to this section Summary
Link to this section Functions
Link to this function
validate(changeset, field, opts \\ [])
View Sourcevalidate(Ecto.Changeset.t(), atom(), list()) :: Ecto.Changeset.t()