DEV Community

Cover image for ๐Ÿ” Build & Run Your Own TOTP Generator in Under 5 Minutes โ€” with Amazon Q Developer
Long Phan
Long Phan

Posted on

4 3 3 3 3

๐Ÿ” Build & Run Your Own TOTP Generator in Under 5 Minutes โ€” with Amazon Q Developer

This is a submission for the Amazon Q Developer "Quack The Code" Challenge: Crushing the Command Line

Context

We all know that Multi-Factor Authentication (MFA) is essential for securing our accounts. But letโ€™s be honestโ€”how many times have you felt frustrated opening your phone, launching the authenticator app, and copying the OTP code every time you're logging in somewhere on your work computer or laptop?

Worse, what if your phone is de*d, lost, or simply not nearby? Youโ€™re locked out.

Thatโ€™s why I built this project: a TOTP (Time-based One-Time Password) generator tool available as both a command-line interface and a lightweight frontend.

It lets you instantly generate TOTP codes from a saved secretโ€”no phone required.

What I Built

I built a TOTP (Time-based One-Time Password) generator tool that runs on both the command line and a simple frontend web interface. This tool solves the problem of securely generating one-time passwords commonly used in 2FA (Two-Factor Authentication) systems.

โš™๏ธ CLI tool: Instantly generates TOTP codes from a shared secret via terminal. It supports auto-copying the generated code using the clipboard.

๐ŸŒ Frontend demo: A minimal web interface that visualizes the TOTP flow and shows the code updating every 30 seconds.

This tool is lightweight and designed for developers who frequently work with authentication flows, or for testing their 2FA setup during app development.

Demo

๐ŸŒ๏ธŽ Live page: https://longphanquangminh.github.io/totp-generator-project/web

After asking Amazon Q Developer to build the application and generate an initial flow diagram, I took the time to deepen my understanding of how TOTP works. I then created my own visual explanation to solidify and share that understanding (with a demo secret key, so it's just fine like that):

๐Ÿ“Š My custom TOTP flow diagram (made with Excalidraw): Link

Diagram

๐Ÿ”‘ Extracting a TOTP Secret Key from a GitHub QR Code
This screenshot shows how I used my CLI tool to scan a QR code (e.g., from GitHub's 2FA setup) and retrieve the base32 secret key.

Demo

When scanning a QR code with my Samsung phone (just once), you can extract the secret key from the QR's value, which typically follows this format: otpauth://[OTP_type]/[issuer]:[user_identity]?secret=[secret_key]&issuer=[issuer]

Camera

For example, if the value is: otpauth://totp/GitHub:longphanquangminh?secret=ggg&issuer=GitHub => Then the secret_key would be ggg

๐Ÿ–ฅ๏ธ๐Ÿ“ฑ Matching OTPs on Both CLI and Web UI
To demonstrate accuracy, I used the same TOTP secret in both the CLI and web tool. As shown below, both generated the same OTP codes, just like a real authenticator app would:

LiveWeb

Code Repository

๐Ÿ”— GitHub Repo: https://github.com/longphanquangminh/totp-generator-project

  • /cli โ€“ Node.js terminal utility with clipboard integration.
  • /web โ€“ Frontend TOTP display tool with diagram and styling.

How I Used Amazon Q Developer

Amazon Q Developer played a huge role in helping me build and polish this tool quickly. Hereโ€™s how I used it:

๐Ÿง  Idea to Execution โ€” Powered by Amazon Q

  1. Logged into Amazon Q Developer via q login from my terminal.
  2. Opened Q Chat via q chat to brainstorm implementation details and flow.
  3. Prompted Q: How do I implement a TOTP generator CLI tool in Node.js that auto-copies the result to clipboard? โ†’ Q provided sample code using otplib and clipboardy. But in this case, after doing some research, I decided to use otpauth instead of otplib because it's newer and offers more flexible customization of the algorithm and time settings.
  4. Used Q to help draw a simple diagram explaining the TOTP flow (time + secret โ†’ HMAC โ†’ OTP).
  5. Asked Q to help improve the CLI experience (formatting, error handling, feedback, timer).
  6. Switched to the frontend: I asked Q to style the TOTP web page, make it responsive, and implement the 30-second countdown bar.
  7. Completed both tools in a much shorter time than building from scratch.

๐Ÿš€ With the help of Amazon Q, I built both the CLI tool and the frontend app in literally under 5 minutes.

AmazonQ

๐Ÿ’ก Tips for Using Amazon Q Developer

  1. Be clear and specific in your prompts.
  2. Ask for architecture and visual explanations tooโ€”not just code.
  3. Iterate with Q! Ask it to improve or adapt to your stack.

Disclaimer

This tool was built for educational purposes and as a submission for the Amazon Q Developer โ€œQuack The Codeโ€ Challenge. Please use it responsibly. Personally, I believe if you're using a work or company-issued computer โ€” especially as a software engineer โ€” it's acceptable to store TOTP secrets locally for convenience, as long as your device is secured. Relying solely on a phone with many apps also carries potential risks.

๐Ÿ‘จโ€๐Ÿ’ป Built by longphanquangminh and Amazon Q Developer

Survey image

Calling All Cloud Developers - Your Insights Matter

Take the Developer Nation Survey and help shape cloud development trends. Prizes await!

Join Today

Top comments (1)

Collapse
 
eren_yeager_a783c55ddf647 profile image
John Bandido โ€ข

Thank you! Now I know how OTP works ๐Ÿ˜‚

Survey image

Calling All Cloud Developers - Your Insights Matter

Take the Developer Nation Survey and help shape cloud development trends. Prizes await!

Join Today