Giter Site home page Giter Site logo

vic / comeonin_ecto_password Goto Github PK

View Code? Open in Web Editor NEW
35.0 3.0 10.0 22 KB

Ecto type for saving encrypted passwords using Comeonin

Home Page: https://github.com/elixircnx/comeonin

License: BSD 3-Clause "New" or "Revised" License

Elixir 100.00%
ecto comeonin password-hash

comeonin_ecto_password's Introduction

Comeonin Ecto Password

A custom Ecto type for storing encrypted passwords using 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:

field :password, Comeonin.Ecto.Password

Then on your changeset simply cast from plain-text params

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:

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`!

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 config

Installation

Available in Hex, the package can be installed as:

Add comeonin_ecto_password to your list of dependencies in mix.exs:

def deps do
  [{:comeonin_ecto_password, "~> 3.0.0"}]
end

comeonin_ecto_password's People

Contributors

aeons avatar hermanverschooten avatar pedrosnk avatar vic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

comeonin_ecto_password's Issues

Password length validation

Hello,
as far as I understand, password is changed to hash as soon as it is casted, which causes trouble with validation. Currently the only way is to use Ecto.Changeset.change, validate length and then do everything else (casting etc.). I believe there should be config option in this library to set up minimal password length, to make changesets look more standard. Alternatively, if there is simpler solution I'm missing, I believe it should be added to README.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.