<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/totp-for-2fa-is-incredibly-easy-to-implement-so-what-s-your-excuse--l4qu5c9o7" -->

---
title: TOTP for 2FA is incredibly easy to implement. So what&#x27;s...
description: TOTP (Time-based One-Time Passwords) for two-factor authentication is straightforward to implement and far superior to SMS-based 2FA. The algorithm involves...
canonical: https://daily.dev/posts/totp-for-2fa-is-incredibly-easy-to-implement-so-what-s-your-excuse--l4qu5c9o7
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: TOTP for 2FA is incredibly easy to implement. So what&#x27;s your excuse? | daily.dev
og:description: TOTP (Time-based One-Time Passwords) for two-factor authentication is straightforward to implement and far superior to SMS-based 2FA. The algorithm involves...
og:url: https://daily.dev/posts/totp-for-2fa-is-incredibly-easy-to-implement-so-what-s-your-excuse--l4qu5c9o7
og:image: https://api.daily.dev/og/posts/l4qU5C9o7.png
og:image:alt: TOTP for 2FA is incredibly easy to implement. So what&#x27;s your excuse?
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# TOTP for 2FA is incredibly easy to implement. So what's your excuse?

**[Drew DeVault](https://daily.dev/sources/drewdevault)** · 3 min read · 0 upvotes · 0 comments

## Summary

TOTP (Time-based One-Time Passwords) for two-factor authentication is straightforward to implement and far superior to SMS-based 2FA. The algorithm involves dividing the Unix timestamp by 30, computing an HMAC-SHA1 with the shared secret, and deriving a 6-digit code. Complete working implementations are provided in both Python and Hare, each under 30 lines of code. TOTP avoids the pitfalls of SMS 2FA — no SIM swapping, no phishing risk, no paid API like Twilio — making it both more secure and easier to implement.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://drewdevault.com/2022/10/18/TOTP-is-easy.html>

---

Tags: [#python](https://daily.dev/tags/python), [#authentication](https://daily.dev/tags/authentication)

[View this post on daily.dev](https://daily.dev/posts/totp-for-2fa-is-incredibly-easy-to-implement-so-what-s-your-excuse--l4qu5c9o7)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"TOTP for 2FA is incredibly easy to implement. So what's your excuse?","url":"https://daily.dev/posts/totp-for-2fa-is-incredibly-easy-to-implement-so-what-s-your-excuse--l4qu5c9o7","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/totp-for-2fa-is-incredibly-easy-to-implement-so-what-s-your-excuse--l4qu5c9o7"},"datePublished":"2026-03-31T12:28:21.555Z","dateModified":"2026-03-31T12:44:26.751Z","description":"TOTP (Time-based One-Time Passwords) for two-factor authentication is straightforward to implement and far superior to SMS-based 2FA. The algorithm involves...","image":"https://media.daily.dev/image/upload/s--OHB84bZF--/f_auto/v1722860399/public/Placeholder%2010","thumbnailUrl":"https://media.daily.dev/image/upload/s--OHB84bZF--/f_auto/v1722860399/public/Placeholder%2010","isAccessibleForFree":true,"articleSection":"Drew DeVault","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Drew DeVault","logo":"https://media.daily.dev/image/upload/s--BGhGBu0U--/f_auto,q_auto/v1774960025/logos/drewdevault?_a=BAMAMiWQ0","url":"https://daily.dev/sources/drewdevault"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/totp-for-2fa-is-incredibly-easy-to-implement-so-what-s-your-excuse--l4qu5c9o7","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python,authentication","timeRequired":"PT3M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Drew DeVault","item":"https://daily.dev/sources/drewdevault"},{"@type":"ListItem","position":3,"name":"TOTP for 2FA is incredibly easy to implement. So what's your excuse?"}]}
```

