secure_password v0.2.2 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)
def changeset(model, params \\ :empty) 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
Functions
Validates and modify the changeset to remove the password
and password_confirmation
fields
and add the hashed password_digest
field.
Options
required
: Do not force the password to be present if set tofalse
. (default:true
)min_length
: Set the minimum length for the password. (default:6
)