Phauxth v0.17.0 Phauxth.Login View Source

Module to handle login.

Link to this section Summary

Functions

Check the password by comparing it with a stored hash

Verify a user’s password

Link to this section Functions

Link to this function check_pass(user, password, crypto, opts) View Source

Check the password by comparing it with a stored hash.

The stored hash, in the user struct, should have password_hash or encrypted_password as a key.

Link to this function verify(params, user_context, opts \\ []) View Source

Verify a user’s password.

Check the user’s password, and return {:ok, user} if login is successful or {:error, message} if there is an error.

If login is successful, you need to either add the user to the session, by running put_session(conn, :user_id, id), or send an api token to the user.

Options

There are two options for the verify function:

  • crypto - the password hashing module to use

    • the default is Comeonin.Bcrypt
  • log_meta - additional custom metadata for Phauxth.Log

    • this should be a keyword list

The check_pass function also has options. See the documentation for the password hashing module you are using for details.

Examples

In the example below, verify is called within the create function in the session controller.

use Phauxth.Login

def create(conn, %{"session" => params}) do
  case verify(params, MyApp.Accounts) do
    {:ok, user} -> handle_successful_login
    {:error, message} -> handle_error
  end
end