martbock/laravel-diceware
Generate secure, memorable diceware passphrases in Laravel. This package offers a simple API for creating word-based passwords from diceware wordlists, with configurable word counts, separators, and multiple languages. Ideal for user-friendly, high-entropy credentials.
martbock/laravel-diceware generates diceware-style passphrases — memorable multi-word passwords built from a word list. Install it with Composer:
composer require martbock/laravel-diceware
The package auto-registers its service provider. Publish the config file to control defaults:
php artisan vendor:publish --tag=diceware-config
Look first at config/diceware.php (word count, separator, word list path) and the package README for the facade/service entry point. The canonical first use case is generating a human-friendly password at account creation, e.g. in a registration controller or an onboarding flow — a six-word passphrase is easy to read out loud and far stronger than a short random string.
Note: v2.1.0 adds Laravel 10 support. If you are on Laravel 10, you can use this package on the latest framework; if you are pinned to Laravel 9 or below, v2.0.0 remains available.
Facade in controllers / actions. The idiomatic usage is a single call from the facade or injected service:
use Martbock\Diceware\Facades\Diceware;
$passphrase = Diceware::generate(); // uses configured word count
$short = Diceware::generate(4); // override word count
Dependency injection for testability. Rather than calling the facade directly inside business logic, inject the underlying generator so you can fake it in tests:
public function __construct(private DicewareGenerator $diceware) {}
public function createUser(array $data)
{
$data['password'] = Hash::make($this->diceware->generate(6));
return User::create($data);
}
Model factories and seeders. Generate deterministic-ish test data by calling the generator in a factory state, or use a fixed word list in tests so assertions are stable.
Admin / service-account provisioning. Combine the generated passphrase with a forced reset on first login. This is where diceware shines: the passphrase can be emailed or read over the phone without being a security liability, and you keep the "human transferable" property that random base64 strings lose.
Custom word lists. Publish or override the word list in config to use a language-specific list, a shorter list (more entropy per word but shorter words), or a domain-specific vocabulary. Keep the list large enough — 7,776 words (the classic diceware list) gives ~12.9 bits per word.
Validation / policy integration. Wrap generation in a small PassphraseService if you need to enforce a minimum word count across the app, and reuse it in a custom Laravel validation rule when you want to verify a user-entered passphrase meets your entropy bar.
Chaining with Laravel's own APIs. If you only need random strings, Str::password() is fine; reach for diceware specifically when memorability matters (credentials a human will type, quote, or dictate).
php artisan config:cache after changing word count or separator in production. Forgetting this is the most common "why is it still 5 words?" bug.illuminate/* constraints and PHP version satisfy the new composer.json before bumping — run composer why-not martbock/laravel-diceware 2.1.0 if in doubt.How can I help you explore Laravel packages today?