MFA handling: TOTP code generation
Automate MFA completion using TOTP code generation with RFC 6238 compliant algorithm

Copy prompt to run with your AI agent
Send this template to your email, or view it on your desktop for the source code.
Get started automating TOTP-based MFA authentication
This template automates Multi-Factor Authentication (MFA) completion using Time-based One-Time Password (TOTP) code generation. It implements the RFC 6238 compliant algorithm to generate 6-digit codes programmatically, extracts TOTP secrets from pages, and automatically fills MFA forms without user interaction. The template includes retry logic to handle time window edge cases and automatically regenerates codes when authentication fails. Perfect for automated authentication workflows and `zero-touch` MFA completion.
Steps
- Navigate to the authentication page with TOTP challenge
- Extract test credentials (email, password) and TOTP secret from the page
- Generate TOTP code using RFC 6238 algorithm (HMAC-SHA1, 30-second windows)
- Fill in email and password fields using Stagehand act
- Fill in TOTP code field with the generated code
- Submit the authentication form