doorman v0.0.4 Doorman.Auth.Bcrypt

Provides functions for hashing passwords and authenticating users using Comonin.Bcrypt.

This module assumes that you have a virtual field named password, and a database backed string field named hashed_password.

Usage

In an Ecto model call use Doorman.Auth.Bcrypt. This will add two functions to your module. hash_password/1 and authenticate/2.

Example

defmodule User do
  use  Ecto.Schema
  use Doorman.Auth.Bcrypt

  import Ecto.Changeset

  def create_changeset(struct, changes) do
    struct
      |> cast(changes, ~w(email password))
      |> hash_password
  end
end

To authenticate a user in your application, you can use authenticate/2:

user = Repo.get(User, 1)
User.authenticate(user, "password")

Summary

Functions

Compares the given password against the given user’ss password

Takes a changeset and turns the virtual password field into a hashed_password change on the changeset

Functions

authenticate(user, password)

Compares the given password against the given user’ss password.

hash_password(changeset)

Takes a changeset and turns the virtual password field into a hashed_password change on the changeset.