Phauxth v1.1.3 Phauxth.Login View Source
Module to handle login.
See the documentation for the verify
function for details.
Link to this section Summary
Link to this section Functions
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.
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
The following function is an example of using verify in a Phoenix controller.
def create(conn, %{"session" => params}) do
case Phauxth.Login.verify(params, MyApp.Accounts) do
{:ok, user} ->
put_session(conn, :user_id, user.id)
|> configure_session(renew: true)
|> success("You have been logged in", user_path(conn, :index))
{:error, message} ->
error(conn, message, session_path(conn, :new))
end
end
In this example, if the login is successful, the user is added to the session, which is then renewed, and then is redirected to the /users page.