Haytni.AuthenticablePlugin (Haytni v0.7.0) View Source
This is a base plugin as it handles basic informations of a user (which are email and hashed password) and their authentication.
Fields:
- email (string)
- encrypted_password (string)
Configuration:
authentication_keys
(default:[:email]
): the key(s), in addition to the password, requested to login. You can redefine it to~W[name]a
, for example, to ask the username instead of its email address.hashing_method
(no default): a module implementing the behaviourExPassword.Algorithm
to hash and verify passwordshashing_options
(a map, no default since they are hash-specific): ExPassword settings for hashing passwords
To support:
- bcrypt:
- add
{:expassword_bcrypt, "~> 0.2"}
indeps/0
to yourmix.exs
- set
:hashing_method
toExPassword.Bcrypt
on the linestack Haytni.AuthenticablePlugin
and alsohashing_options: %{cost: 10}
- add
- argon2:
- add
{:expassword_argon2, "~> 0.2"}
indeps/0
to yourmix.exs
- set
:hashing_method
toExPassword.Argon2
on the linestack Haytni.AuthenticablePlugin
and alsohashing_options: %{type: :argon2id, threads: 2, time_cost: 4, memory_cost: 131072}
- add
stack Haytni.AuthenticablePlugin,
authentication_keys: [:email],
hashing_method: ExPassword.Bcrypt,
hashing_options: %{
cost: 10,
}
Routes:
haytni_<scope>_session_path
(actions: new/create, delete): the generated routes can be customized through the following parameters when you call YourAppWeb.Haytni.routes/1:- login_path (default:
"/session"
): custom path assigned to the sign-in route - logout_path (default: same value as login_path): the path for th sign out route
- logout_method (default:
:delete
): the HTTP method to use for the user to log out, in case where the default DELETE method were not well supported by your clients
# lib/your_app_web/router.ex defmodule YourAppWeb.Router do # ... scope ... do YourAppWeb.Haytni.routes( login_path: "/login", logout_path: "/logout", logout_method: :get ) end # ... end
- login_path (default:
Link to this section Summary
Functions
Authentificates a user.
Callback implementation for Haytni.Plugin.find_user/3
.
Hashes a password.
Callback implementation for Haytni.Plugin.invalid?/3
.
The translated string to display when credentials (password and/or email by default) are wrong.
Callback implementation for Haytni.Plugin.on_delete_user/4
.
Callback implementation for Haytni.Plugin.on_email_change/4
.
Callback implementation for Haytni.Plugin.on_failed_authentication/5
.
Callback implementation for Haytni.Plugin.on_logout/3
.
Callback implementation for Haytni.Plugin.on_registration/3
.
Callback implementation for Haytni.Plugin.on_successful_authentication/6
.
Converts the parameters received for authentication by the controller in a %Ecto.Changeset{}
to handle and validate
user inputs according to plugin's configuration (authentication_keys
).
Returns true
if password matches user's current hash (encrypted_password field)
Callback implementation for Haytni.Plugin.validate_password/3
.
Callback implementation for Haytni.Plugin.validate_update_registration/3
.
Link to this section Functions
Specs
authenticate( conn :: Plug.Conn.t(), module :: module(), config :: Haytni.AuthenticablePlugin.Config.t(), session_params :: Haytni.params() ) :: Haytni.repo_nobang_operation(Plug.Conn.t())
Authentificates a user.
Returns:
{:ok, user}
if crendentials are correct and user is valid{:error, changeset}
if credentials are incorrect or user is invalid (rejected by aHaytni.Plugin.invalid?
callback by a plugin in the stack)
Callback implementation for Haytni.Plugin.find_user/3
.
Specs
hash_password( password :: String.t(), config :: Haytni.AuthenticablePlugin.Config.t() ) :: String.t()
Hashes a password.
Returns the hash of the password after having hashed it
Callback implementation for Haytni.Plugin.invalid?/3
.
Specs
invalid_credentials_message() :: String.t()
The translated string to display when credentials (password and/or email by default) are wrong.
Callback implementation for Haytni.Plugin.on_delete_user/4
.
Callback implementation for Haytni.Plugin.on_email_change/4
.
Callback implementation for Haytni.Plugin.on_failed_authentication/5
.
Callback implementation for Haytni.Plugin.on_logout/3
.
Callback implementation for Haytni.Plugin.on_registration/3
.
on_successful_authentication(conn, user, multi, keywords, module, config)
View SourceCallback implementation for Haytni.Plugin.on_successful_authentication/6
.
Specs
session_changeset( config :: Haytni.AuthenticablePlugin.Config.t(), request_params :: Haytni.params() ) :: Ecto.Changeset.t()
Converts the parameters received for authentication by the controller in a %Ecto.Changeset{}
to handle and validate
user inputs according to plugin's configuration (authentication_keys
).
Specs
valid_password?( user :: Haytni.nilable(Haytni.user()), password :: String.t(), config :: Haytni.AuthenticablePlugin.Config.t() ) :: boolean()
Returns true
if password matches user's current hash (encrypted_password field)
Callback implementation for Haytni.Plugin.validate_password/3
.
Callback implementation for Haytni.Plugin.validate_update_registration/3
.