zizaco/confide
Confide is a Laravel authentication package that provides ready-made user registration, login, logout, password resets, and email confirmation, with role and permission support via Entrust. A classic choice for adding complete auth scaffolding to legacy Laravel 4/5 apps.
Confide is a Laravel 4–era authentication package. Treat the first hour as "confirm the app can still boot this package" before writing any feature code.
composer.json you need a Laravel 4.2-compatible release (the 0.4.x/dev-master line). Run composer require zizaco/confide, then register the service provider and facade in app/config/app.php:'providers' => [
'Zizaco\Confide\ConfideServiceProvider',
],
'aliases' => [
'Confide' => 'Zizaco\Confide\ConfideFacade',
],
php artisan config:publish zizaco/confide
php artisan migrate --package="zizaco/confide"
The generated users table includes email, password, confirmation_code, confirmed, and remember-token columns. If you already have a users table, copy the relevant columns into your own migration and set user_model in app/config/packages/zizaco/confide/config.php.
use Zizaco\Confide\ConfideUser;
use Zizaco\Confide\ConfideUserInterface;
class User extends Eloquent implements ConfideUserInterface
{
use ConfideUser;
protected $table = 'users';
public $rules = [
'username' => 'required|unique:users',
'email' => 'required|email|unique:users',
'password' => 'required|min:6|confirmed',
'password_confirmation' => 'required',
];
}
Look first at app/config/packages/zizaco/confide/config.php (user_model, email_field, login_field, email_confirmation, throttling keys), then Zizaco\Confide\Confide — that class is the real API surface (create, save, logAttempt, logout, confirm, forgotPassword, resetPassword, user, check).
First use case: a login/register/logout flow. Register by building the model and calling save() (Confide hashes the password and generates a confirmation code). Log in through Confide::logAttempt rather than Auth::attempt, because Confide performs its own credential, confirmation, and throttle checks.
// Registration
$user = new User;
$user->username = Input::get('username');
$user->email = Input::get('email');
$user->password = Input::get('password');
$user->password_confirmation = Input::get('password_confirmation');
if ($user->save()) {
return Redirect::to('login')->with('notice', 'Check your email to confirm.');
}
// Login
if (Confide::logAttempt(Input::only('email', 'password'), Input::get('remember'))) {
return Redirect::intended('dashboard');
}
Controller-first, not middleware-first. Confide has no built-in route filter. The typical day-to-day pattern is a UsersController with getLogin, postLogin, getLogout, getRegister, postRegister, getConfirm, forgotPassword, resetPassword, and protecting routes with a filter that calls Confide::check():
Route::filter('auth', function () {
if (Confide::guest()) {
return Redirect::guest('login');
}
});
Centralize credential handling. Use Confide::logAttempt($credentials, $remember) everywhere. It respects the configured login_field (email or username), checks confirmed, and applies lockout. Do not mix Auth::attempt and Confide::logAttempt in the same app; they maintain separate code paths and can disagree about sessions and hashing.
Use the facade for state, the trait for persistence. Confide::user(), Confide::check(), and Confide::guest() are convenience wrappers; Auth::user() should return the same Eloquent model after a Confide login. Prefer one convention per codebase.
Password reminders are two separate calls. Requesting a reset emails a token; resetting verifies it:
// send
Confide::forgotPassword(Input::get('email'));
// consume
if (Confide::resetPassword(Input::get('password'), Input::get('password_confirmation'), Input::get('token'))) {
return Redirect::to('login');
}
Email confirmation. When email_confirmation is enabled, logAttempt rejects unconfirmed users. Build a ConfirmController that calls Confide::confirm($code) or $user->confirm($code), then redirect with a friendly message. Disable confirmation in config for internal apps to remove this branch entirely.
Pair with Entrust for authorization. Confide answers "who is logged in"; Entrust (Zizaco\Entrust) answers "what may they do." Put EntrustUserTrait on the same User model and check permissions in filters or policies. This combination was the canonical Laravel 4 stack.
Testing pattern. Use database transactions or migrate in setUp. For controller tests, either seed a real user and call the login endpoint, or mock the facade:
Confide::shouldReceive('logAttempt')->once()->andReturn(true);
Prefer real-user tests for auth flows; mocks hide trait behavior (hashing, confirmation).
Extension point: if you must customize behavior, subclass the facade-backed Confide class or override trait methods on the model, then bind your class in a service provider. Avoid editing package files under vendor/.
save(). The trait hashes password only when it is dirty. Bulk updates via query builder or User::update() bypass this and store plaintext. Always assign to the model and call save(), or use Confide::save($user, $attributes).password_confirmation must be present on the model for the confirmed validation rule to pass. Setting $user->password without $user->password_confirmation produces confusing validation errors.$user->password and re-assign it, the trait may hash an already-hashed value. Only set plaintext passwords from request input.confirmed when debugging failed logins. logAttempt returns false for unconfirmed users with no distinct exception. Log the user's confirmed and confirmation_code state before assuming bad credentials.user_model and login_field are read at runtime. Changing them in config without updating the migration/table columns causes silent failures. login_field defaults to email; switching to username requires that column and valid credentials in logAttempt.remember_token column or logins will not persist.User model already defines save(), confirm(), or getAuthIdentifier(), PHP trait resolution can shadow your method. Alias the trait method or call parent::save() carefully. The same applies when combining Confide and Entrust traits; method name collisions are the usual failure mode.password, confirmation_code, and confirmed in $guarded/$fillable to prevent them being set from request arrays. Confide does not protect these for you.Session::regenerate() after successful login if your app relies on it, and verify Confide::logout() clears the remember cookie on the deployed PHP version.timestamp defaults and index lengths can fail; copy the migration into your app and adjust before deploying.Confide::user() return a model after login? (4) is the user confirmed? (5) does config user_model point to the right class? Most issues resolve here.Confide::logAttempt with Auth::attempt, use Laravel's PasswordBroker for resets, and port confirmation to a signed URL or middleware. Do this behind feature tests that assert login, logout, reset, and authorization behavior before deleting the package.How can I help you explore Laravel packages today?