Phauxth v0.12.1-rc.0 Phauxth.Login View Source
Module to handle login.
Phauxth.Login.verify/2
checks the user’s password, and returns
{: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.
If you are using two-factor authentication, you need to first check
the user schema for otp_required: true
and, if necessary, redirect
the user to the one-time password input page.
Options
There is one option:
identifier - the name which is used to identify the user (in the database)
- this should be an atom, and the default is
:email
- this should be an atom, and the default is
Examples
In the example below, Phauxth.Login.verify is called within the create function in the session controller.
def create(conn, %{"session" => params}) do
case Phauxth.Login.verify(params, MyApp.Accounts) do
{:ok, user} -> handle_successful_login
{:error, message} -> handle_error
end
end
Link to this section Summary
Link to this section Functions
Check the password by comparing it with a stored hash.
This uses Comeonin.Bcrypt by default. You can define a custom module to use a different crypto module in the following way:
defmodule Phauxth.Argon2Login do
use Phauxth.Login.Base
defdelegate check_pass(user, password, opts), to: Comeonin.Argon2
end
Then you can use the Phauxth.Argon2Login.verify function to check the user’s password.
Verify a user’s password.
Examples
The example below shows how you can use this function in the create function of a Phoenix session controller:
def create(conn, %{"session" => params}) do
case Phauxth.Login.verify(params, MyApp.Accounts) do
{:ok, user} -> handle_successful_login
{:error, message} -> handle_error
end
end