Download the PHP package yeonik/login-defense without Composer

On this page you can find all versions of the php package yeonik/login-defense. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package login-defense

login-defense

CI

Progressive login protection for PHP: track failed attempts, escalate to a captcha challenge, then to a timed lockout — with the escalation policy explicit, configurable and tested. Framework-agnostic core, thin Laravel bridge included.


Why this exists

"Why not just use the framework's rate limiter?" The built-ins are binary — under the limit you pass, over it you're blocked. Real attacks live in between: slow credential stuffing that stays under any sane limit, distributed attempts that never trip a per-IP counter. Production needs graduated friction — cheap for legitimate users, increasingly expensive for automation — plus an explicit, auditable policy for when each step engages. This package makes that escalation a first-class, configurable, tested object instead of scattered if statements in a controller.

"Why is the core framework-agnostic?" Because abuse mitigation is domain logic, not HTTP plumbing. The rules for when to demand a captcha do not depend on whether the request arrived through Laravel, Symfony, or a queue worker. Keeping the decision in pure PHP behind PSR interfaces means it is testable without booting a framework — and the core test suite proves it by running with no framework installed at all.


Install

Requires PHP 8.3+. The core depends only on PSR interfaces (simple-cache, event-dispatcher, clock, http-client, http-factory, http-server-middleware) — installing this package pulls in no framework.

The optional Laravel bridge supports Laravel 12 and 13, both covered by CI, and is auto-discovered when illuminate/support is present.

Publish the config (Laravel):


The escalation ladder

The decision is a pure function of the failure count on a key and the config:

Failures on the key Decision
< captcha_after (default 3) Allow
< lockout_after (default 6) RequireCaptcha
>= lockout_after Lockout, retryAfter = min(base · mult^extra, max)

retryAfter starts at base_seconds (60s) and doubles with each further failure until it hits max_seconds (1h), where it stays. All thresholds and windows are configurable in config/login-defense.php.


Usage

Framework-agnostic core

The application owns its authentication; the guard owns the escalation decision.

A ready-made PSR-15 middleware is included for stacks that prefer to gate the route directly.

Laravel

Attach the middleware to your login route:

It reads the identifier (email or username), the client IP and captcha_token from the request, and short-circuits with 429 (locked out) or 422 (captcha required). Reporting the auth outcome stays with your controller via LoginGuard::recordFailure() / recordSuccess() — the middleware enforces consequences, it does not guess whether your credentials were correct. Set login-defense.enabled to false and the middleware becomes a pass-through, with Laravel's default behaviour unchanged.


Security decisions, and why

Each of these is a deliberate call, commented at the point it is made in the code.

Tradeoff: counter atomicity

The bundled PsrCacheAttemptStore is backed by PSR-16, which has no atomic increment. Its increment() is a read-modify-write, so under concurrent requests two processes can both read a sub-threshold count, both add one, and both be let through — the effective threshold can be exceeded by roughly the number of in-flight requests.

This is not hidden. AttemptStore is an interface precisely so a backend with a native atomic counter (e.g. Redis INCR) can implement the same contract race-free, with no change to the decision logic above it. For production under sustained or adversarial load, back the tracker with such a store. The bundled PSR-16 store is correct for development, low-traffic apps, and the test suite.


The architecture is the point

Two layers, one seam, visible in the directory structure:

Core/ imports nothing from Bridge/ and nothing from Illuminate\*. The proof is a CI job that installs no framework at all and runs the core suite against it:

Job PHP Framework
core 8.3, 8.4 none installed
bridge 8.3, 8.4 Laravel 12 and 13 (Orchestra Testbench)

The bridge job runs four cells — PHP 8.3/8.4 × Laravel 12/13 — with each Laravel major pinned to its matching Testbench major (12 → Testbench 10, 13 → Testbench 11).

Every push runs composer audit, pint --test, phpstan analyse (level 6, larastan on the bridge, no baseline, no ignores) and both suites.


Scope

Out of scope, on purpose:


License

MIT — see LICENSE.


All versions of login-defense with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
psr/simple-cache Version ^3.0
psr/event-dispatcher Version ^1.0
psr/clock Version ^1.0
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^2.0
psr/http-server-middleware Version ^1.0
psr/http-server-handler Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package yeonik/login-defense contains the following files

Loading the files please wait ...