Validate Time-based One-time Passwords (TOTP) secrets directly within your n8n workflow using custom Python code. Integrate secure 2FA logic with this versatile n8n template.
Download this n8n workflow template and start using it instantly.
This specialized n8n template provides a highly flexible method for verifying Time-based One-time Passwords (TOTP) codes. Unlike standard methods that might require setting up specific n8n credentials, this n8n workflow uses a robust, self-contained Python script to handle the entire verification process—from base32 decoding to HMAC-SHA1 generation.
The primary value of this n8n workflow is its independence. It allows you to dynamically retrieve the user's TOTP secret (e.g., from a database) and immediately check the user-provided code against the current time interval. This is essential for building custom sign-in or secure action verification flows, offering a powerful core logic flow control within your overall n8n automation.
This automation is initiated by the Manual Trigger n8n node, typically used for testing or when executed as a sub-workflow.
totpsecretexample (the user's Base32 secret key) and the codetoverify_example (the 6-digit code provided by the user).hmac, hashlib). The script decodes the Base32 secret, calculates the current time interval counter, generates the expected TOTP code using HMAC-SHA1, and compares it to the input code. It returns a status of 1 (valid) or 0 (invalid).1, the n8n workflow proceeds down the 'true' branch for successful authentication; if 0, it proceeds down the 'false' branch, allowing for custom error handling or credential rejection.To deploy this n8n workflow, follow these steps:
input.item.json.totpsecret_example).$json.body.secret and $json.body.code). When clicking ‘Test workflow’ (Manual Trigger n8n node): Serves as the starting point for testing this n8n template. In a live system, this n8n trigger would be replaced by a production trigger.
EXAMPLE FIELDS (Set n8n node): A utility node used solely for testing. It injects sample data (a totpsecretexample and codetoverifyexample) into the n8n workflow structure before validation.
TOTP VALIDATION (Code n8n node): The functional core. This n8n node contains a Python script implementing the RFC 6238 standard for TOTP. Key configurations include setting the language to Python and defining the verifytotp function to compare the calculated token with the input code.
IF CODE IS VALID (IF n8n node): A core logic flow control n8n node. It checks the status output ($json.status) from the preceding Code n8n node. If the status equals 1, the validation is successful, directing the n8n workflow accordingly.
Ensure flawless email campaigns using an AI Quality Gate. This n8n workflow uses GPT-5 to analyze rendered HTML, check for broken content, and automatically block flawed newsletters, preventing bad customer experiences.

Use this robust n8n workflow to automatically validate mobile deep links embedded in code during GitHub PR creation. This specialized n8n template executes local shell scripts and reports results directly back to GitHub PR comments.

Automate cleaning and verifying large lead lists stored in Google Sheets using this effective n8n workflow and the Hunter.io API. Get real-time status and confidence scores.

Use this advanced n8n workflow to automatically read contact data from Google Sheets, validate fields (Name, Email, Mobile), handle errors via Gmail, and sync successful records to LEDGERS. An essential n8n templates example for reliable data management.









































