Repository navigation
Hashing
Laravex provides one-way password hashing through Laravex.Hashing.Hash. Passwords are hashed with PBKDF2-HMAC-SHA256 — a deliberately slow key-derivation function that resists brute-force and GPU attacks.
Never use
Laravex.Encryption.Cryptfor passwords.Cryptis reversible (AES-256-GCM);Hashis not. See Encryption.
Control the PBKDF2 work factor via BCRYPT_ROUNDS in .env (the name is intentionally Laravel-compatible):
BCRYPT_ROUNDS=12
The environment variable is multiplied by 1 000 to get the actual PBKDF2 iteration count (default 12 × 1000 = 12 000). Increase this value on more powerful hardware:
BCRYPT_ROUNDS=14 # 14 000 iterations
hashed = Laravex.Hashing.Hash.make("secret-password")
# => "pbkdf2:12000:<salt_hex>:<hash_hex>"A fresh 16-byte salt is generated via :crypto.strong_rand_bytes/1 for every call, so the same password always produces a different stored value.
Laravex.Hashing.Hash.check("secret-password", hashed)
# => true | falsecheck/2 reconstructs the hash using the salt and iteration count embedded in the stored value, then compares it in constant time using :crypto.hash_equals/2 to prevent timing attacks. It handles both the current four-part format and a legacy three-part format (iterations inferred from env).
When you increase BCRYPT_ROUNDS, existing hashes are out of date. Check this on login and transparently rehash:
if Laravex.Hashing.Hash.needs_rehash?(user.password) do
new_hash = Laravex.Hashing.Hash.make(plain_password)
model.save(%{user | password: new_hash})
endneeds_rehash?/1 returns true when the iteration count embedded in the hash does not match the current BCRYPT_ROUNDS × 1000. The Authentication guard calls this automatically via Guard.attempt/2 — you only need it in custom authentication flows.
Hashes are stored as plain text strings:
pbkdf2:<iterations>:<salt_hex>:<hash_hex>
| Field | Example |
|---|---|
| Algorithm | pbkdf2 |
| Iterations | 12000 |
| Salt | 32 lowercase hex chars (16 bytes) |
| Hash | 64 lowercase hex chars (32 bytes) |
A legacy format (hashed:<payload>) is also recognized by check/2 for backward compatibility, though new hashes are never produced in that format.
If you define a :hashed cast on an Eloquex model field, the value is automatically hashed when assigned and before persisting — you never handle the raw hash manually:
defmodule App.Models.User do
use Laravex.Eloquex.Model, table: "users"
def casts do
%{password: :hashed}
end
end# Plain text in → hash stored automatically
App.Models.User.create(%{"name" => "Alice", "password" => "secret"})See Eloquex-Mutators for full details on casts.
- Encryption — Reversible AES-256-GCM encryption
-
Authentication — The session guard that calls
Hash.check/2on login -
Passwords — The password reset broker that calls
Hash.make/1
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