Customization | laravel-suspicious-login-rust | Spatie       

 SPATIE  

laravel-suspicious-login-rust
=============================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-suspicious-login-rust](https://spatie.be/docs/laravel-suspicious-login-rust/v1)  Customization

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-suspicious-login-rust/v1) 

  Customization    
- [ Introduction ](https://spatie.be/docs/laravel-suspicious-login-rust/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-suspicious-login-rust/v1/support-us)
- [ Installation ](https://spatie.be/docs/laravel-suspicious-login-rust/v1/installation-and-setup)
- [ Usage ](https://spatie.be/docs/laravel-suspicious-login-rust/v1/usage)
- [ Detection ](https://spatie.be/docs/laravel-suspicious-login-rust/v1/detection)
- [ Testing ](https://spatie.be/docs/laravel-suspicious-login-rust/v1/testing)
- [ Changelog ](https://spatie.be/docs/laravel-suspicious-login-rust/v1/changelog)
- [ Customization ](https://spatie.be/docs/laravel-suspicious-login-rust/v1/customization)

 Customization
=============

###  On this page 

1. [ Typed config and environment ](#content-typed-config-and-environment)
2. [ Selected types ](#content-selected-types)

Typed config and environment
--------------------------------------------------------------------------------------------------------------------------------------------

- Override the typed section after provider defaults:

```
use spatie_suspicious_login::{Config, drivers::Geolocation, policy::Policy, service_provider};

let app = laravel::Application::configure()
    .with_providers(|providers| { providers.add(service_provider()); })
    .with_config(|config, _| {
        config.set(Config {
            policy: Policy::monitor_only(),
            geolocation: Geolocation::disabled(),
            queue: Some("security".into()),
            ..Config::default()
        });
    });
```

Environment defaults use the framework's validated `Env` reader:

- `SUSPICIOUS_LOGIN_ENABLED`, default `true`.
- `SUSPICIOUS_LOGIN_MEDIUM_THRESHOLD` / `SUSPICIOUS_LOGIN_HIGH_THRESHOLD`, defaults `40` / `70`.
- `SUSPICIOUS_LOGIN_RETENTION_DAYS`, default `365`, must be positive and fit the stored time range.
- `SUSPICIOUS_LOGIN_MAILER`, `SUSPICIOUS_LOGIN_QUEUE_CONNECTION`, `SUSPICIOUS_LOGIN_QUEUE`, unset for application defaults.
- `SUSPICIOUS_LOGIN_GEOLOCATION`, one of `ipinfo`, `cloudflare`, `maxmind`, `null`; default `ipinfo`.
- `IPINFO_TOKEN`, optional; `MAXMIND_DATABASE_PATH`, default `storage/app/geoip/GeoLite2-City.mmdb`.
- `SUSPICIOUS_LOGIN_LOCATION_CACHE_TTL`, default `604800` seconds.
- `SUSPICIOUS_LOGIN_IP_REPUTATION`, one of `null`, `tor`, `abuseipdb`; default `null`.
- `ABUSEIPDB_KEY`, required for AbuseIPDB; `SUSPICIOUS_LOGIN_TOR_URL`, default `https://check.torproject.org/torbulkexitlist`.
- `SUSPICIOUS_LOGIN_REPUTATION_CACHE_TTL`, default `86400` seconds.
- Invalid typed environment values fail framework validation rather than silently accepting defaults.
- Tokens are redacted from driver debug output. Keep secrets in environment configuration, not source control.
- Invalid setup returns `Error::UnknownLocationDriver`, `Error::UnknownReputationSource`, `Error::MissingAbuseIpDbKey` or `Error::MaxMindDatabase`. The database variant includes its path and original error source.
- `Config::properties` receives the request and optional encoded account ID. It returns JSON metadata before policy selection. Explicit `LoginOptions::properties` take precedence.
- Read nested keys with `attempt.property("tenant.region")`. Never include passwords or access tokens.

Selected types
--------------------------------------------------------------------------------------------------

- `service_provider_with::<M, F, W>(fingerprinter)` binds `SuspiciousLogin<M, F, W>`. Inject that exact monitor type in your handlers.
- Default type parameters are `AttemptRecord`, `CookieFingerprinter` and `SuspiciousLoginMail`.
- `M` implements `AttemptModel` on a native `#[model]` with a string primary key. Implement `insert_attempt`, `mark_blocked`, `attempts_query` and `attempt`. Use native create/update/query APIs so normal model defaults, table/connection settings and hooks remain available. Pruning is a native bulk delete and does not run per-record delete hooks.
- The query must expose `id`, `user_type`, `user_id`, `successful`, `blocked` and `observed_at`; the supplied migration also stores `identifier` and JSON `data`. Decode persisted blocked status in `attempt`. All recording, history, failures, assessment updates and pruning use this selected model.
- `F` implements `Fingerprinter`. `UserAgentFingerprinter` strips dotted versions before hashing, so browser updates remain familiar without cookies. Equal user agents on different devices are indistinguishable. Cookie fingerprints are random identities protected by native encryption.
- `W` implements the native `Mailable` trait plus `WarningMail::for_attempt`. Build any native plain-text or view-backed message. Escape untrusted data when rendering HTML. Its optional `queue_connection()` and `queue()` overrides take precedence over package settings. `Config::mailer` chooses a native mailer.
- The integration suite contains a complete custom model on a separate connection, stateless fingerprinter and native mailable. It exercises them through real login requests, queued-mail assertions and pruning.
- For a custom block response, replace `Policy::blocked_response` with a function returning `laravel::Error`. Helpers still persist blocked status and log out before returning it.
- To avoid blocking, omit `Action::Block`.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
