Repository navigation
Passwords
Laravex includes a full password-reset flow through Laravex.Auth.Password. Secure tokens are stored in the password_reset_tokens table and expire after a configurable window.
# config/auth.exs
%{
"passwords" => %{
"users" => %{
"provider" => "users",
"table" => "password_reset_tokens",
"expire" => 60, # minutes before token expires
"throttle" => 60 # seconds before another reset link can be requested
}
}
}The password_reset_tokens table is created by the default migration (0001_01_01_000000_create_users_table.ex):
# database/migrations/0001_01_01_000000_create_users_table.ex
{:create, "password_reset_tokens", [
{:string, "email", primary: true},
{:string, "token"},
{:timestamp, "created_at", nullable: true}
]}case Laravex.Auth.Password.send_reset_link(%{"email" => email}) do
:sent -> # link emailed — redirect with status message
:throttled -> # another link was recently sent — tell the user to wait
:user -> # email not found — respond the same as :sent to avoid enumeration
end
Internally send_reset_link/1:
- Looks up the user via
model.find_by_email/1 - Checks the throttle window (default 60 seconds between requests)
- Generates a 64-character random token, stores its SHA-256 hash in
password_reset_tokens - Sends a
Laravex.Auth.ResetPasswordNotificationviaLaravex.Notifications.Notifier
The plain-text token is embedded in the reset URL:
https://example.com/reset-password/<token>?email=user%40example.com
credentials = %{
"email" => request.params["email"],
"token" => request.params["token"],
"password" => request.params["password"]
}
case Laravex.Auth.Password.reset(credentials) do
:reset -> # success — redirect to login with confirmation
:token -> # invalid or expired token
:user -> # user not found
end
reset/1:
- Validates that all three fields are present
- Verifies the token against the stored hash using constant-time comparison
- Checks the token has not expired (
expireminutes fromcreated_at) - Hashes the new password via Hashing (
Laravex.Hashing.Hash.make/1) - Saves the new password to the user record
- Deletes the used token from
password_reset_tokens
For multi-broker setups, pass the broker name:
# Named broker
Laravex.Auth.Password.send_reset_link(%{"email" => email}, broker: "admins")
# Manual token lifecycle
token = Laravex.Auth.Password.create_token("user@example.com")
valid? = Laravex.Auth.Password.token_valid?("user@example.com", token)
Laravex.Auth.Password.delete_token("user@example.com")The broker map contains name, table, expire, throttle, and provider fields derived from config/auth.exs.
The Starter-Kits command (./artisan install:starter-kit) scaffolds these routes in routes/auth.ex:
Router.get("/forgot-password", &App.Http.Controllers.AuthController.show_forgot/1,
name: "password.request")
Router.post("/forgot-password", &App.Http.Controllers.AuthController.send_reset/1,
name: "password.email")
Router.get("/reset-password/{token}", &App.Http.Controllers.AuthController.show_reset/1,
name: "password.reset")
Router.post("/reset-password", &App.Http.Controllers.AuthController.reset/1,
name: "password.update")And the corresponding Blade templates in resources/views/auth/.
- Tokens are SHA-256 hashed before storage; plain-text tokens never touch the database.
- Constant-time comparison (
:crypto.hash_equals/2) prevents timing attacks. - The
send_reset_link/1function returns the same response (:useris treated as:sentin the starter-kit controller) to prevent email enumeration. - Tokens expire after
expireminutes and are deleted immediately on successful use.
-
Authentication —
Guard.attempt/2and session login -
Hashing —
Hash.make/1used to hash the new password -
Starter-Kits —
install:starter-kitfor complete auth scaffolding
Laravex — Laravel-faithful application skeleton & runtime for Elixir.
GitHub
·
Docs
·
Limitations
·
Laravel Docs
Not affiliated with Laravel LLC or the Elixir core team. Built to feel like Laravel on the BEAM.
- Home
- Installation
- Configuration
- Directory-Structure
- Request-Lifecycle
- Service-Container
- Service-Providers
- Deployment
- Routing
- Middleware
- CSRF-Protection
- Controllers
- Requests
- Responses
- Views
- Blade-Templates
- Asset-Bundling
- Session
- Validation
- Error-Handling
- Logging
- Artisan-Console
- Broadcasting
- Cache
- Collections
- Events
- File-Storage
- Helpers
- HTTP-Client
- Localization
- Notifications
- Pipeline
- Queues
- Rate-Limiting
- Strings
- Task-Scheduling