Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vic/comeonin_ecto_password
Ecto type for saving encrypted passwords using Comeonin
https://github.com/vic/comeonin_ecto_password
comeonin ecto password-hash
Last synced: 3 months ago
JSON representation
Ecto type for saving encrypted passwords using Comeonin
- Host: GitHub
- URL: https://github.com/vic/comeonin_ecto_password
- Owner: vic
- License: bsd-3-clause
- Created: 2016-01-22T10:08:32.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-10-25T14:34:58.000Z (over 5 years ago)
- Last Synced: 2024-05-02T10:17:35.660Z (9 months ago)
- Topics: comeonin, ecto, password-hash
- Language: Elixir
- Homepage: https://github.com/elixircnx/comeonin
- Size: 21.5 KB
- Stars: 35
- Watchers: 3
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Ecto custom type for storing encrypted password using Comeonin. (ORM and Datamapping)
- fucking-awesome-elixir - comeonin_ecto_password - Ecto custom type for storing encrypted password using Comeonin. (ORM and Datamapping)
- awesome-elixir - comeonin_ecto_password - Ecto custom type for storing encrypted password using Comeonin. (ORM and Datamapping)
README
A [custom Ecto type](https://hexdocs.pm/ecto/Ecto.Type.html#summary) for storing encrypted passwords using [Comeonin](https://github.com/elixircnx/comeonin)
For ecto 1 compatibility use the `ecto-1` branch.
_Version 3.x is compatible with `comeonin` ~> 5.0_, use version 2.x for compatibility with older versions.
## Usage
On your schema, define secure fields with this type:
```elixir
field :password, Comeonin.Ecto.Password
```Then on your changeset simply cast from plain-text params
```elixir
changeset
|> cast(attrs, [:password])
|> validate_required([:password])
```After casting the password will already be encrypted
in the changeset, and can be saved to your table's
string column.To check for validity, do something like:
```elixir
user = Repo.get_by(User, email: "[email protected]")
Comeonin.Ecto.Password.valid?("plain_password", user.password)
```## Configuration
In your environment file, choose one of `Pbkdf2`, `Bcrypt`, `Argon2`.
The default is 'Pbkdf2`, but you still need to include it in your `mix.exs`!```elixir
config :comeonin, Ecto.Password, Pbkdf2# when using pkbdf2
config :comeonin, :pbkdf2_rounds, 120_000
config :comeonin, :pbkdf2_salt_len, 512# when using bcrypt
config :comeonin, :bcrypt_log_rounds, 14
```Also, be sure to look at [comeonin](https://github.com/elixircnx/comeonin#installation) [config](http://hexdocs.pm/comeonin/Comeonin.Config.html)
## Installation
[Available in Hex](https://hex.pm/packages/comeonin_ecto_password), the package can be installed as:
Add comeonin_ecto_password to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:comeonin_ecto_password, "~> 3.0.0"}]
end
```