Credential stuffing explained: reused passwords and account takeover

TL;DR

Difficulty: Intermediate

Credential stuffing replays email and password pairs leaked from other sites against your login form, looking for the ones your customers reused.

  • Password reuse is the root cause: a correct password is not proof it is the real customer, so the attack can succeed against a shop that did nothing wrong.
  • The attacker is after stored value, a saved card, personal data and a confirmed account to sell on, and spreads the run across thousands of addresses to look like ordinary sign ins.
  • AI has made the bots cheaper and faster to build, and the AI written login code is measurably weaker, missing the defensive layer by default.
  • I defend in layers: rate limiting and throttling with Rack Attack, checking passwords against the Have I Been Pwned range API, a second factor, device and anomaly detection, bot protection without a privacy hostile CAPTCHA, and alerting on the pattern.
  • Cucumber tests lock each defence in, and a pen test with Kali tools before release confirms the throttles trip and the responses stay identical.

Credential stuffing is one of the most common attacks on any site with a login, and one of the least understood. An attacker takes a list of email addresses and passwords leaked from some other company and tries every pair on your login form, keeping the ones your customers reused. Here is why that works, what the attacker does with the accounts they open, and how I defend a Rails or Solidus shop against it.

The attack that replays old passwords against your shop

Credential stuffing is one of the most common attacks against any site with a login, and one of the least understood by the people who own those sites. The name sounds like jargon. The idea behind it is simple. Somewhere else, on a forum or an airline or a games service that had nothing to do with you, a database of email addresses and passwords leaked. An attacker takes that list, points it at your login form, and tries every pair to see which ones still open an account. The pairs that work were reused. That is the whole trick, and it works because most people use the same password in more than one place.

This article is about why that attack is so effective, what the attacker is really after once they are in, why artificial intelligence has made the whole thing faster and less expensive to run, and how I defend the Ruby on Rails and Solidus shops I build against it.

I will use one invented business throughout. Calder Cycles is an online bike shop in Leeds (caldercycles.example). It sells bikes, parts and servicing, and its customers have accounts: saved delivery addresses, order history, loyalty points worth real money off, and a stored card token for one click reorders. It is run by Devlin. The shop and Devlin are made up. The attack, and every defence against it, is real.

Why password reuse is the whole game

Start with the root cause, because everything else follows from it. People reuse passwords. The same eight characters that protect a loyalty account also protect an inbox, a bank, a work login and twenty shops. Surveys put the share of people who reuse passwords well above half, and the reason is human, not stupid: nobody can remember forty strong passwords, so one memorable one gets spread around.

That habit turns one company's breach into everybody's problem. When a service is breached and its passwords leak, those passwords do not stay with that service. They go into collections that circulate freely, some with billions of pairs in them, sorted and deduplicated and ready to use. The attacker does not need to break your security at all. They borrow a breach from somewhere with weaker security than yours and let your own customers' reused passwords do the work.

So the uncomfortable truth is that a credential stuffing attack can succeed against a shop that did nothing wrong. Your passwords were never stolen. Your code was never broken into. A customer reused a password that leaked elsewhere, and the attacker simply tried it on your door. This is why the defence cannot only be "store passwords properly". You have to assume the password is already known to someone, and make that not be enough.

How the attack actually works

A credential stuffing run has three parts: a list, a target and a lot of automation.

The list is the breach data. Call it ten million email and password pairs. Most of them are useless against Calder Cycles, because most of those people never shopped there. The attacker does not know which ones are useful yet. That is what the run is for.

The target is your login form. It is a plain HTTP request. A browser sends the same request when a real customer signs in: a POST to a login path with an email and a password in the body. Nothing stops a script from sending that request too, as fast as the server will answer.

The automation tries the pairs at scale. In the crudest form it is a short loop that posts each pair and reads the response. Here is the shape of it, written deliberately as harmless pseudocode rather than anything you could point at a real shop:

for email, password in breach_list:        # millions of pairs
    response = post(login_url, email, password)
    if response looks_like_success:
        save(email, password)               # a hit: this account opened
    rotate_proxy_and_wait_a_little()

The attacker never sees most of these attempts succeed. A run with a one in a thousand hit rate is considered good, and one in a thousand against ten million pairs is still ten thousand opened accounts. The economics are brutal precisely because the base is so large.

The part that makes it hard to spot is the hiding. A naive attack comes from one address and is trivial to block. A real one is spread across thousands of residential proxy addresses, each used for only a handful of attempts, with pauses between them and a browser fingerprint that looks like a phone on a home connection. The traffic is designed to look like thousands of ordinary customers signing in, because that is exactly what it is pretending to be.

What the login response gives away

The attacker reads your responses to learn which pairs are worth keeping. That is where a lot of shops quietly help them. If a wrong password returns one message and a correct password with a blocked account returns a different one, the attacker learns the password was right even when they cannot get in. If the login page says "no account with that email" for unknown addresses and "wrong password" for known ones, you have just handed over a way to confirm which of the ten million emails even have an account, before a single password is tried. Small differences in wording, in timing, or in the HTTP status code all leak signal. The defence starts with giving the same answer, in the same time, to every failed attempt.

What the attacker is really after

Opening the account is not the goal. It is the key to the things behind it. What those things are depends on the shop, and a bike shop like Calder Cycles has more of them than its owner thinks.

  • Stored value. Loyalty points, store credit, gift card balances. These spend like cash and often have weaker fraud checks than a card payment, because the shop already treats them as money it owns.
  • A stored payment method. If a card token sits on the account for one click reorders, the attacker can order expensive, easy to resell goods to a fresh address. The real customer pays.
  • Personal data. Name, address, phone, order history, date of birth. This is worth money on its own, and it is the raw material for the next, more convincing scam against the same person.
  • The account itself, as a foothold. A working email and password pair, confirmed against your shop, is more valuable than an unconfirmed one from a breach. It gets sold on at a premium, and it gets tried against the customer's bank and inbox next.

Example: a quiet Tuesday at Calder Cycles

At two in the morning the shop's login traffic triples, but it is spread so thinly across so many addresses that nothing looks alarming on a casual glance. Over four hours, roughly nine hundred accounts open. By breakfast the attacker has filtered the hits into three buckets: accounts with loyalty points, accounts with a saved card, and accounts with neither. The points get spent on gift cards. Two saved cards order a top end wheelset each, shipped to a reshipping address. The rest are bundled and sold on.

The first Devlin hears of it is a customer email: "Why have my points gone, and who ordered wheels to an address in a different city?" Nothing in the shop was broken. Every one of those logins used a correct password. That is what makes account takeover so corrosive to trust: from the system's point of view, the attacker was the customer.

How artificial intelligence has raised the risk

Two things have changed, and they pull in the same direction.

The first is that automated attacks have become faster and less expensive to run. The tooling to rotate proxies, solve simple challenges, mimic a real browser and tune a run used to take skill to assemble. A capable assistant now writes a serviceable version of it in an afternoon, and the parts that used to be a barrier, like making the traffic look human, are increasingly handled by services you can rent by the hour. Credential stuffing was already a volume game. Lowering the cost of volume makes every list worth running against more targets, including small shops that once flew under the radar.

The second is that more of the code defending the login was itself written by an assistant, and that code is measurably weaker on security. The Veracode GenAI Code Security Report 2025 found that AI generated code contains 2.74 times more vulnerabilities than human written code.1 An Ox Security analysis of more than three hundred repositories in 2025 found the same ten anti patterns in 80 to 100 per cent of AI generated code.2 Other research has found that around 45 per cent of AI generated code introduces a vulnerability from the OWASP Top 10.3

For this attack in particular, the danger is specific. A login that an assistant produces will usually work. A customer can sign in, which is the only thing a quick test checks. What a generated login almost never has, unless someone insists on it, is the unglamorous defensive layer: a rate limit, identical responses for every failure, a check against known breached passwords, an option for a second factor, an alert when the pattern of failed logins turns strange. None of that shows up when you click through the happy path. It only shows up on the night of the attack, by which point nobody remembers why the login was supposed to be boring.

How I defend against it

There is no single switch. Credential stuffing is defended in layers, and the point of the layers is that the attacker has to beat all of them while a real customer barely notices any. Here is what I build in, on the Rails and Solidus shops I ship.

Rate limiting and throttling

The first layer makes volume expensive. A login form should not answer thousands of attempts a minute from the same source, and it should slow down hard when it sees a burst. Rails has a built in rate_limit in recent versions, and I pair it with Rack Attack, a small gem that sits in front of the app and throttles or blocks requests by rule.

# config/initializers/rack_attack.rb
class Rack::Attack
  # Slow repeated login attempts from one address
  throttle("logins/ip", limit: 10, period: 60) do |req|
    req.ip if req.path == "/login" && req.post?
  end

  # Slow repeated attempts against one account, whatever the source address
  throttle("logins/email", limit: 5, period: 60) do |req|
    if req.path == "/login" && req.post?
      req.params.dig("session", "email").to_s.downcase.presence
    end
  end
end

The second throttle matters more than the first. Spreading an attack across thousands of addresses defeats a limit keyed only on the address. Keying a limit on the email being attacked means that even an attacker with endless addresses still cannot hammer one account, and a run that walks through a breach list one account at a time runs into a wall on every one of them.

Checking passwords against known breaches

This attacks the root cause directly. If the password a customer is trying to use is already sitting in a public breach collection, it is not a secret, and letting them set it is building the next takeover in advance. I check new and changed passwords against the Have I Been Pwned Pwned Passwords set, using its range API, which is designed so you never send the password or its full hash anywhere.

The method is neat. You hash the password with SHA1, take the first five characters of that hash, and ask the service for every breached hash that starts with those five. It sends back a few hundred suffixes. You check for your password's hash in that list locally. The service never learns which password, or even which full hash, you asked about.

require "digest"
require "net/http"

def breached_count(password)
  hash = Digest::SHA1.hexdigest(password).upcase
  prefix, suffix = hash[0, 5], hash[5..]
  body = Net::HTTP.get(URI("https://api.pwnedpasswords.com/range/#{prefix}"))
  body.each_line do |line|
    found_suffix, count = line.strip.split(":")
    return count.to_i if found_suffix == suffix
  end
  0
end

If the count comes back above zero, I do not block the customer outright, I tell them plainly that this password has appeared in a breach and ask them to choose another. This follows the NIST digital identity guidance, which recommends screening new passwords against breach lists and, notably, advises against forcing people to change passwords on a schedule for no reason.45 The goal is fewer reused passwords on the shop, not more friction.

A second factor, device recognition and anomaly detection

A password, even a good one, is one thing you know, and credential stuffing proves that one thing is not enough. Offering a second factor, a time based one time code (TOTP) from an app, or a passkey, means a correct password alone no longer opens the account. I make it easy to switch on, and I strongly encourage it for any account that holds stored value or a saved card.

Between no second factor and a full one sits a cheaper, quieter layer: recognising the situation. The shop remembers the devices and rough locations a customer normally signs in from. A login that matches is waved through. A login that is correct but strange, a new device, a new country, the first success after a long string of failures on that account, triggers a step up: a one time code to the email on file before the session is trusted. The real customer sees this only on the rare genuinely new device. The attacker, logging in from a residential proxy on the other side of the world, sees it every time.

Bot protection without a privacy hostile CAPTCHA

The traffic itself can be filtered before it ever reaches a password check, and it is worth doing without reaching for a CAPTCHA that makes every customer prove they are human by labelling traffic lights. Those puzzles punish real people, lean on a third party that watches your visitors, and are increasingly solved by the very automation they are meant to stop.

I prefer quieter signals. A real browser runs JavaScript, holds a session cookie, loads the page before it posts the form, and does not submit a login in eighty milliseconds. A proof of work challenge, invisible to a human, costs a script real time at scale. Honeypot fields that a human never fills but a crude bot does, and modern privacy respecting challenges that only escalate to something visible when a request already looks automated, catch a large share of the volume without taxing ordinary customers. The principle is to spend the friction on the suspicious request, not on everyone.

Alerting on the pattern

The last layer assumes the others will one day be beaten and makes sure you find out the same night, not from a customer a week later. A credential stuffing run has a shape: a surge in failed logins, a sudden rise in attempts against accounts that do not exist, a spike in password reset requests, successful logins clustered on fresh devices. I wire these into the shop's monitoring, with error and performance monitoring through AppSignal, so an unusual pattern raises an alert while it is still happening. Early detection turns a disaster into an inconvenience: you can force a password reset on the accounts that opened, freeze stored value, and watch the suspicious orders before they ship.

Why testing and pen testing catch this

Every one of those layers is a promise, and a promise that nobody checks is a promise that quietly breaks. So I write the defences down as tests that run on every change, in plain enough language that Devlin could read them. I build Rails and Solidus shops with behaviour driven tests in Cucumber on top of the unit tests, and the login defences get scenarios of their own:

Feature: Login resists credential stuffing

  Scenario: repeated wrong passwords for one account are throttled
    Given the account "rider@caldercycles.example" exists
    When a script tries 20 wrong passwords for it within a minute
    Then the login is throttled
    And every failed attempt returns the same message

  Scenario: a password from a known breach is refused on sign up
    When a customer tries to register with a password known to be breached
    Then the shop asks them to choose a different password

A scenario like that fails the day someone removes the throttle, or changes the login to leak a different message for a known account, or quietly drops the breach check to make registration smoother. The test turns an invisible security property into something the build will not ship without. This is the difference between code I own and understand and a black box: when a defence matters, there is a test standing on it, and a failing test stops the release.

On top of the automated tests, I pen test before release with the same tools an attacker would use, run from Kali Linux: Burp Suite and OWASP ZAP to probe the login and watch exactly what each response gives away, and to drive the kind of automated attempts a real run would make, so I can confirm the throttles trip, the messages stay identical, and the alerts fire. Static analysis with Brakeman sweeps the Rails code for the known weak spots. The point of doing the attack myself, in a controlled way, is simple: I would rather be the one who finds the gap.

This is also what makes the work insurable and verifiable rather than a matter of trust. The code is readable and owned, not a mystery bundle nobody can explain. Every defensive path has a test on it. When a customer, an insurer or an auditor asks how the shop stands up to account takeover, the answer is a list of named tests and a pen test report, not a shrug and a hope.

A short, honest close

Credential stuffing is not a clever attack. It is a patient one, and it runs on a weakness none of us can fully fix in other people: they reuse passwords. You cannot stop the breaches happening elsewhere. What you can do is make a correct but reused password not be enough on its own, make a high volume attack expensive and loud, and make sure that the night it happens, you are the one who notices first.

If you run a shop with customer accounts and you are not sure which of these layers you actually have, that is worth an honest look rather than a guess. In the free workshop we go through your login and account flows together, find the gaps, and agree what to lock in as tests. The first two weeks of work are on me.

If you run a shop with customer accounts and you are not sure which of these layers you actually have, book the free workshop: we go through your login and account flows together, find the gaps, and the first two weeks of work are on me.

Sources

  1. 1.
  2. 2.

    Ox Security, analysis of more than 300 repositories, 2025, https://www.ox.security/

  3. 3.

    Research reported across 2024 and 2025 finding that roughly 45 per cent of AI generated code introduces an OWASP Top 10 vulnerability; see the Veracode and related datasets above.

  4. 4.

    National Institute of Standards and Technology, Digital Identity Guidelines, Special Publication 800 63B, https://pages.nist.gov/800-63-3/sp800-63b.html

  5. 5.

    Troy Hunt, Have I Been Pwned, Pwned Passwords range API, https://haveibeenpwned.com/API/v3#PwnedPasswords

Shelter

I’m running the London Marathon for Shelter. Sunday 25 April 2027

My personal fundraiser. Shelter, the National Campaign for Homeless People Limited, registered charity 263710 (England and Wales) and SC002327 (Scotland), registered with the Fundraising Regulator.