Overview
This tutorial walks through implementing Fingerprint to prevent account takeover. Account takeover (ATO) occurs when an attacker gains access to a real user’s account, often through stolen credentials, automated login abuse at scale, phishing, or other attacks aimed at your sign-in flow. You’ll begin with a starter app that includes a mock login page and a basic login flow. From there, you’ll add the JavaScript agent to identify each visitor and use server-side logic with Fingerprint data to detect and block automated login attempts. By the end, you’ll have a sample app that rejects high-risk traffic and can be customized to fit your use case and business rules. This tutorial uses just plain JavaScript and a Node server with SQLite on the backend. For language- or framework-specific setups, see the quickstarts.Estimated time: < 15 minutes
This tutorial requires the Bot Detection Smart Signal, which is only available
on paid plans.
Prerequisites
Before you begin, make sure you have the following:- A copy of the starter repository (clone with Git or download as a ZIP)
- Node.js (v20 or later) and npm installed
- Your favorite code editor
- Basic knowledge of JavaScript
1. Create a Fingerprint account and get your API keys
- Sign up for a free Fingerprint trial, or log in if you already have an account.
- After signing in, go to the API keys page in the dashboard.
- Save your public API key, which you’ll use to initialize the JavaScript agent.
- Create and securely store a secret API key for your server. Never expose it on the client side. You’ll use this key on the backend to retrieve full visitor information through the Fingerprint Server API.
2. Set up your project
- Clone or download the starter repository and open it in your editor.
Terminal
- This tutorial uses the
account-takeoverfolder. The project is organized as follows:
public
index.html - Login page
index.js - Front-end logic to handle login
server
server.js - Serves static files and login endpoint
db.js - SQLite database connection
accounts.js - Login validation and account takeover checks
.env.example - Example environment variables
- From the
account-takeoverdirectory, install dependencies:
Terminal
- Copy or rename
.env.exampleto.env, then add your Fingerprint API keys:
Terminal
- Start the server:
Terminal
- Visit http://localhost:3000 to view the mock login page from the starter app. You can test the basic login form using the included test account (
demo@example.com/password123) and clicking Log in. - Then try to log in using the included headless bot test script
test-bot.js. While the app is running, executenode test-bot.jsand observe that the automated script logs in successfully. By default, the server does not distinguish between bots and real users.
Terminal
3. Add Fingerprint to the frontend
In this step, you’ll load the JavaScript agent when the page loads and trigger identification when the user clicks Log in. The JavaScript agent returns both avisitor_id and an event_id. Instead of relying on the visitor_id from the browser, you’ll send the event_id to your server along with the login payload. The server will then call the Fingerprint Events API to securely retrieve the full identification details, including bot detection and other signals.
- At the top of
public/index.js, load the JavaScript agent:
public/index.js
-
Make sure to change
regionto match your workspace region (e.g.,eufor Europe,apfor Asia,usfor Global (default)). -
Near the bottom of
public/index.js, the Log in button already has an event handler for submitting the credentials. Inside this handler, request visitor identification from Fingerprint using theget()method and include the returnedevent_idwhen sending the login to the server:
public/index.js
get() method sends signals collected from the browser to Fingerprint servers, where they are analyzed to identify the visitor. The returned event_id acts as a reference to this specific identification event, which your server can later use to fetch the full visitor details.
For lower latency in production, use Sealed Client Results to return full identification details as an encrypted payload from the get() method.
4. Receive and use the event ID to get visitor insights
Next, pass theeventId through to your login logic, initialize the Fingerprint Node Server SDK, and fetch the full visitor identification event so you can access the trusted visitor ID, Bot Detection, and other Smart Signals.
- In the backend, the
server/server.jsfile defines the API routes for the app. Update the/api/loginroute there to also extracteventIdfrom the request body and pass it into theattemptLoginfunction:
server/server.js
- The
server/accounts.jsfile contains the logic for handling logins. Start by importing and initializing the Fingerprint Node Server SDK there, and load your environment variables withdotenv.
server/accounts.js
-
Make sure to change
regionto match your workspace region (e.g.,EUfor Europe,APfor Asia,Globalfor Global (default)). -
Update the
attemptLoginfunction to accepteventIdand use it to fetch the full identification event details from Fingerprint:
server/accounts.js
eventId, the getEvent method will retrieve the full data for the visitor identification event. The returned object will contain the visitor ID, IP address, device, and browser details, and Smart Signals like bot detection, browser tampering detection, VPN detection, and more. You’ll use those fields in the next steps to decide whether a sign-in attempt looks like account takeover or other abuse.
You can see a full example of the event structure and test it with your own device in the demo playground.
For additional checks to ensure the validity of the data coming from your frontend, view how to protect from client-side tampering and replay attacks.
5. Block logins after too many recent failed attempts
Takeover attempts and password guessing often produce many failures from the same device, even when the attacker rotates usernames. Once you can reliably associate attempts with a Fingerprint visitor ID, you can persist outcomes and rate-limit or block visitors that exceed a threshold of recent failures—before or alongside other checks. The starter app includes a SQLitelogin_attempts table for this demo. Each row records the visitor ID, account email, whether the attempt succeeded, and a timestamp:
SQLite database tables
- Add helper functions at the bottom of
server/accounts.jsto record failures and count how many failed attempts a visitor had in the last 24 hours:
server/accounts.js
- In
attemptLogin, after you callgetEvent, readvisitor_idfromevent.identification. Then before validating the password, block visitors with too many recent failures. On any failed outcome in this flow, record a row withlogFailedAttemptso later attempts stay counted.
attemptLogin should look like this:
server/accounts.js
6. Block unrecognized devices from logging in
Valid passwords are often used from new devices during account takeover. A practical pattern is to require a prior successful login from the same visitor ID for that user before treating the session as routine, or to step up authentication (MFA, OTP, etc.) when that history is missing. This tutorial is simplified and will block unrecognized devices from logging in for demonstration purposes. For the first successful login for an account there is no history yet, so allow it and establish a baseline. For later logins, if the account already has at least one successful login stored, but this visitor ID has never succeeded for that email, block as an unrecognized device.- Add helpers to query and record successful attempts by email and visitor ID:
server/accounts.js
- Within
attemptLogin, after the password matches, add the check before returning and logging a successful attempt. If the account already has successful logins but this visitor ID has not, log a failed attempt and return an error:
server/accounts.js
7. Block bots
Automated scripts and headless browsers often show up in account takeover workflows. Fingerprint Bot Detection helps differentiate real users from abusive automation. Fingerprint returnsnot_detected if no bot activity is found, good for known bots (for example known search engines, verified AI agents, etc.), and bad for other automation.
- Continuing in
attemptLogin, add a bot check on the sameeventyou already fetched, then a Suspect Score check (optional but useful as a secondary layer for suspicious traffic):
server/accounts.js
This is a minimal example to show how to implement Fingerprint. In a real
application, make sure to implement proper security practices, error checking,
and password handling that align with your production standards.
8. Test your implementation
Now that everything is wired up, you can test the full protected login flow.- Start your server if it isn’t already running and open http://localhost:3000:
Terminal
- Log in once with a valid test account (
demo@example.com/password123). You will see a success response, and that browser’s visitor ID will be recorded as a known trusted device for that account. - Try several failed login attempts using the wrong password from the same browser. After three failures within the rolling time window, the recent failed attempts check blocks that visitor ID, including with the correct password, until the window rolls forward or you reset the demo database.
- Reset the demo database, then log in successfully again from your browser so there is a known trusted device on file for
demo@example.com. - With that successful browser session in place, open the demo in a completely different browser. Attempt to log in with the correct credentials. Since the new browser has no prior successful login, the login will be rejected as an unrecognized device
- Next, run the headless test script from the
account-takeoverdirectory. It uses the correct credentials but because it is a headless browser, the login will be rejected as a bot:
Terminal
Terminal