How a login is scored | laravel-suspicious-login-go | Spatie       

 SPATIE  

laravel-suspicious-login-go
===========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-suspicious-login-go](https://spatie.be/docs/laravel-suspicious-login-go/v1)  Basic-usage  How a login is scored

 Version   v1      

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

  How a login is scored    
- [ Introduction ](https://spatie.be/docs/laravel-suspicious-login-go/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-suspicious-login-go/v1/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-suspicious-login-go/v1/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-suspicious-login-go/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-suspicious-login-go/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-suspicious-login-go/v1/changelog)
- [ Testing ](https://spatie.be/docs/laravel-suspicious-login-go/v1/testing)
- [ Releasing ](https://spatie.be/docs/laravel-suspicious-login-go/v1/releasing)
- [ About us ](https://spatie.be/docs/laravel-suspicious-login-go/v1/about-us)

Basic usage
-----------

- [ Getting started ](https://spatie.be/docs/laravel-suspicious-login-go/v1/basic-usage/getting-started)
- [ How a login is scored ](https://spatie.be/docs/laravel-suspicious-login-go/v1/basic-usage/how-a-login-is-scored)
- [ Determine the preset ](https://spatie.be/docs/laravel-suspicious-login-go/v1/basic-usage/choosing-a-preset)
- [ Customizing presets ](https://spatie.be/docs/laravel-suspicious-login-go/v1/basic-usage/customizing-presets)
- [ Working with login attempts ](https://spatie.be/docs/laravel-suspicious-login-go/v1/basic-usage/working-with-login-attempts)
- [ Adding custom properties ](https://spatie.be/docs/laravel-suspicious-login-go/v1/basic-usage/adding-custom-properties)
- [ Recording logins manually ](https://spatie.be/docs/laravel-suspicious-login-go/v1/basic-usage/recording-logins-manually)

Available checks
----------------

- [ Overview ](https://spatie.be/docs/laravel-suspicious-login-go/v1/available-checks/overview)
- [ New device ](https://spatie.be/docs/laravel-suspicious-login-go/v1/available-checks/new-device)
- [ New IP address ](https://spatie.be/docs/laravel-suspicious-login-go/v1/available-checks/new-ip)
- [ New country ](https://spatie.be/docs/laravel-suspicious-login-go/v1/available-checks/new-country)
- [ Impossible travel ](https://spatie.be/docs/laravel-suspicious-login-go/v1/available-checks/impossible-travel)
- [ Allowed and blocked countries ](https://spatie.be/docs/laravel-suspicious-login-go/v1/available-checks/country)
- [ Failed attempts ](https://spatie.be/docs/laravel-suspicious-login-go/v1/available-checks/failed-attempts)
- [ Credential stuffing ](https://spatie.be/docs/laravel-suspicious-login-go/v1/available-checks/credential-stuffing)
- [ Unusual time ](https://spatie.be/docs/laravel-suspicious-login-go/v1/available-checks/unusual-time)
- [ Suspicious user agent ](https://spatie.be/docs/laravel-suspicious-login-go/v1/available-checks/suspicious-user-agent)
- [ IP reputation ](https://spatie.be/docs/laravel-suspicious-login-go/v1/available-checks/ip-reputation)
- [ Multiple countries ](https://spatie.be/docs/laravel-suspicious-login-go/v1/available-checks/multiple-countries)

Responding to suspicious logins
-------------------------------

- [ Notifying users ](https://spatie.be/docs/laravel-suspicious-login-go/v1/responding-to-suspicious-logins/notifying-users)
- [ Blocking logins ](https://spatie.be/docs/laravel-suspicious-login-go/v1/responding-to-suspicious-logins/blocking-logins)
- [ Writing your own actions ](https://spatie.be/docs/laravel-suspicious-login-go/v1/responding-to-suspicious-logins/writing-your-own-actions)
- [ Using events ](https://spatie.be/docs/laravel-suspicious-login-go/v1/responding-to-suspicious-logins/using-events)

Advanced usage
--------------

- [ Creating custom checks ](https://spatie.be/docs/laravel-suspicious-login-go/v1/advanced-usage/creating-custom-checks)
- [ Geolocation drivers ](https://spatie.be/docs/laravel-suspicious-login-go/v1/advanced-usage/geolocation-drivers)
- [ IP reputation drivers ](https://spatie.be/docs/laravel-suspicious-login-go/v1/advanced-usage/ip-reputation-drivers)
- [ Device fingerprints ](https://spatie.be/docs/laravel-suspicious-login-go/v1/advanced-usage/device-fingerprints)
- [ Using your own model ](https://spatie.be/docs/laravel-suspicious-login-go/v1/advanced-usage/using-your-own-model)

 How a login is scored
=====================

###  On this page 

1. [ Risk levels ](#content-risk-levels)
2. [ An example ](#content-an-example)
3. [ What counts as known ](#content-what-counts-as-known)
4. [ Logins that aren't recorded ](#content-logins-that-arent-recorded)

Every time someone tries to log in through `Authenticator`, the package stores a `LoginAttempt`. Failed attempts are only recorded, because there is nothing to protect yet. Successful logins go through a few more steps:

1. The package builds the attempt, adds properties, chooses a preset once, then looks up the IP address using your geolocation driver. `NonePreset` skips lookup and assessment.
2. It runs every check of the preset. Each check compares the login with earlier logins, recent activity on the same IP, or a configured signal.
3. Flagged checks add points. The total is capped at 100.
4. The preset turns the score into a risk level.
5. The attempt is saved with its score, level and reasons, then `Recorded` is dispatched.
6. Medium and high risk dispatch `Detected`, then run the actions for that level in order.

All of this happens during the login request, right after native authentication. That's why an action can still block the login. Propagate errors from the helper. On recording, assessment or action errors the session helper also logs out, rather than leaving an unassessed session signed in. Manual recording does not perform that extra session cleanup.

Risk levels
-----------------------------------------------------------------------------------------

With `DefaultPreset` and default thresholds:

ScoreRisk level0 to 39`suspiciouslogin.Low`40 to 69`suspiciouslogin.Medium`70 to 100`suspiciouslogin.High`A low risk login is recorded and nothing else happens. Medium and high risk logins are considered suspicious. Threshold comparisons are inclusive. See [customizing presets](/docs/laravel-suspicious-login-go/v1/basic-usage/customizing-presets).

An example
--------------------------------------------------------------------------------------

Anna has been logging in every morning from Antwerp on her MacBook. Tonight, someone logs in from New York using Firefox on Windows. `DefaultPreset` sees a new device (+25), a new IP (+10), and a new country (+30). Antwerp to New York in ten hours is possible by plane, so impossible travel passes. Assuming the other checks pass, the score is 65, which is medium risk.

```
*attempt.RiskScore      // 65
*attempt.RiskLevel      // suspiciouslogin.Medium
attempt.IsSuspicious() // true
attempt.Reasons.V      // []suspiciouslogin.Reason with check, score and explanation
```

What counts as known
--------------------------------------------------------------------------------------------------------------------

Familiarity checks only compare with earlier logins that were successful and not blocked. Failed attempts and blocked logins never make a device, IP address or country known. Otherwise an attacker could shape the user's history before logging in.

The first login is never flagged for a new device, IP or country. Earlier logins without a country do not establish country history.

Logins that aren't recorded
---------------------------------------------------------------------------------------------------------------------------------------

Restoring a remember-me session doesn't call the helper and isn't recorded. Native `auth.Attempt` or `auth.Login` also won't record anything unless you replace them with the helper.

Set `Enabled` to false to disable helper recording. Explicit `RecordSuccessfulLogin`, `RecordFailedLogin` and `Assess` calls still work. Failed logins and `NonePreset` leave `RiskScore`, `RiskLevel` and `Reasons` nil.

 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)
