secure_password v0.6.0 SecurePassword
Provides an easy way to interact with hashed password for Ecto models.
Example
defmodule User do
use Ecto.Schema
use SecurePassword
import Ecto.Changeset
schema "users" do
field :email, :string
field :name, :string
has_secure_password
end
@required_fields ~w(email)
@optional_fields ~w(name password)
def changeset(model, params \\ :invalid) do
model
|> cast(params, @required_fields, @optional_fields)
|> with_secure_password(min_length: 8)
end
end
Summary
Functions
Checks if the model password if valid
Validates and modify the changeset to remove the password
and password_confirmation
fields
and add the hashed password_digest
field
Macros
Defines the needed fiels in the schema.
Expects password_digest
row to exist in the database