
A correct password no longer proves much. Credentials leak, get reused and get phished. Many teams already add two-factor authentication, but a login that passes every check can still look wrong: a new phone, a new country, two cities an hour apart. Risk-based login scoring tries to catch that. A new Laravel package from Spatie, Laravel Suspicious Login, is a good example of the idea, and it shows the decisions any team has to make, whatever the stack.
How risk scoring works
The principle is simple. After a login succeeds, the system adds up points for signals that differ from the user's history. According to the package announcement, those signals are the device, the IP address, the location and past logins. A new device might add 25 points, a new country 30. Thresholds then map the total to an action: do nothing, email the user, or block.
This is not authentication. It sits after it. It does not replace passkeys or two-factor, and the package says so itself. Think of it as a smoke detector, not a lock.
The useful part is that the weights are yours. A payroll tool used by staff in two countries has a different normal than a consumer app used by travellers. Flagging any third country at a high score makes sense in the first case and would be noise in the second.
The trade-offs to weigh
Every signal has a cost. Before you switch anything on, think through these points.
- False positives. Users change phones, clear cookies and use VPNs. Device identification in this package relies on an encrypted cookie, so clearing cookies makes the next login look like a new device. That alone should not lock anyone out.
- Privacy. Location lookup means sending IP addresses to a geolocation service, unless you use a local database. For some businesses and some regulators, that is a real decision, not a detail. Know where the data goes and say so in your privacy policy.
- Support load. A blocked login needs a clear message and a human path back in. If the only route is a ticket, you have moved the cost from security to support.
- Operations. Alert emails are usually queued. If no worker is running, no alert is sent. Test the whole path, not only the scoring.
Block rarely, notify often
Our view is that blocking should be the exception. An email that says "was this you?" costs the user two seconds and gives you a signal. A block costs a customer a session, and sometimes a customer.
A sensible split looks like this:
- Low score: record it and move on.
- Medium score: notify the user. Let the login go through.
- High score: block, or require a second factor, but only where the data is sensitive enough to justify the friction.
Stepping up to a second factor on high risk is often better than a hard block. The real user can still get in, and the attacker with a stolen password cannot. The package lets you write custom actions, so this kind of response is possible without changing the core logic.
Also allow different rules for different groups. Staff accounts, customers and shared demo accounts do not share the same risk. One global policy will be too strict for some and too weak for others.
Roll it out in observe mode first
The most useful advice in the source is for existing apps: start in a mode that only records scores and fires events, with no emails and no blocks. We agree, and we would make it a rule for any detection feature.
Run it for a few weeks. Then look at real data:
- How many logins land in each risk band?
- Which signal produces the most flags?
- Are the flagged logins actually suspicious, or just travel and new phones?
Adjust weights and thresholds from that evidence. Only then turn on notifications, and later blocking for the groups that need it. This avoids the worst outcome of a new security feature: locking out your best users on day one.
A few practical checks before production:
- Confirm that login routes carry the cookie middleware the device identity needs.
- Decide on the geolocation provider, and what happens when it is rate limited or unavailable.
- Make sure remembered sessions behave as you expect. This package, for example, does not score logins restored from a "remember me" cookie.
- Write the blocked-login message and the recovery path before you need them.
Takeaway
Risk scoring is a cheap, useful layer, but it is a policy, not a switch. Start in observe mode, tune the weights to how your users really behave, notify before you block, and be clear about where location data goes. Do that and you get early warning on stolen credentials without punishing the people you built the product for.
Source: Laravel News
