Passwords मात्र अपर्याप्त छन्। Data breaches ले हरेक वर्ष अरबौं credentials expose गर्छन्, र credential stuffing attacks सफल हुन्छन् किनभने मानिसहरू passwords reuse गर्छन्। Time-based One-Time Passwords (TOTP) ले एउटा second factor generate गर्छ जुन हरेक ३० seconds मा बदलिन्छ — shared secret र current time बाट cryptographically derived। Attacker ले तपाईंको password चोर्यो भने पनि ६-digit code बिना login गर्न सक्दैन।
नेपालमा cybersecurity awareness बढ्दो छ। Nepal Police Cyber Bureau र CERT Nepal ले account takeover attacks रिपोर्ट गर्छन् जुन weak authentication बाट हुन्छन्। यो guide मा TOTP को mathematical foundation देखि real-world attacks र best practices सम्म सबै कुरा छ — developers र security-conscious professionals दुवैका लागि।
TOTP Codes अहिलेनै Generate र Test गर्नुहोस्
Secure TOTP secret generate गर्नुहोस्, QR code scan गर्नुहोस् र real-time 6-digit codes verify गर्नुहोस्। SHA-1, SHA-256, SHA-512 test गर्नुहोस्। निःशुल्क, server मा कुनै storage छैन।
TOTP के हो? Time-Based One-Time Passwords कसरी काम गर्छन्
TOTP को full form हो Time-based One-Time Password। यो RFC 6238 (2011) मा defined छ, HOTP (RFC 4226) को extension हो। Core idea: shared secret key र current time प्रयोग गरेर एउटा short numeric code generate गर्नु, र दुवै sides (server र user को authenticator app) ले independently same code produce गर्नु — communicate नगरी।
TOTP Algorithm Step by Step
import hmac, hashlib, struct, time, base64
def generate_totp(secret_base32: str, digits: int = 6, period: int = 30) -> str:
# Step 1: Base32 secret decode गर्नुहोस्
secret_bytes = base64.b32decode(secret_base32.upper())
# Step 2: T calculate गर्नुहोस् (time counter)
T = int(time.time()) // period
# Example: 1710835200 / 30 = 57027840
# Step 3: T लाई 8-byte big-endian मा pack गर्नुहोस्
T_bytes = struct.pack('>Q', T)
# Step 4: HMAC-SHA1 compute गर्नुहोस्
hmac_result = hmac.new(secret_bytes, T_bytes, hashlib.sha1).digest()
# Step 5: Dynamic Truncation
offset = hmac_result[-1] & 0x0F
code_int = struct.unpack('>I', hmac_result[offset:offset + 4])[0] & 0x7FFFFFFF
# Step 6: Modulo reduction र zero-padding
return str(code_int % (10 ** digits)).zfill(digits)
Time Window र Validity
Current UNIX time: 1,710,835,246
T = floor(1,710,835,246 / 30) = 57,027,841
यो code valid छ: ३० seconds को लागि
Servers ले T-1 (previous window) र T+1 (next window) पनि accept गर्छन्:
- Clock skew handle गर्न
- User को typing time को लागि
Total effective validity: 60-90 seconds
नेपाल सन्दर्भ: Cybersecurity Awareness
Nepal Rastra Bank ले financial institutions लाई 2FA mandatory गर्न directives जारी गरेको छ। नेपालका प्रमुख banks (NIC Asia, Nabil, Kumari) ले already mobile banking apps मा TOTP implement गरेका छन्। IT professionals को लागि आफ्नो GitHub, AWS, Google Workspace accounts मा TOTP enable गर्नु आवश्यक छ।
TOTP vs SMS OTP vs Hardware Keys: Security Comparison
| Method | Phishing Resistant | SIM Swap Resistant | Works Offline | Security Level |
|---|---|---|---|---|
| SMS OTP | छैन | छैन (major weakness) | Cellular signal चाहिन्छ | Weak |
| TOTP (RFC 6238) | Partial (relay possible) | छ | छ (offline) | Good |
| FIDO2/WebAuthn Passkey | छ (domain-bound) | छ | छ | Excellent |
| Hardware Key (YubiKey) | छ | छ | छ | Excellent |
SMS 2FA किन Critically Weak छ
SIM Swap Attack:
1. Attacker ले तपाईंको carrier लाई social engineering गर्छ
("मेरो phone हरायो, number नयाँ SIM मा transfer गर्नुहोस्")
2. Carrier ले तपाईंको number attacker को SIM मा transfer गर्छ
3. Attacker ले password reset request गर्छ → SMS उसको phone मा
4. Account fully compromised
नेपालमा SIM swap cases Nepal Police Cyber Bureau ले report गरेका छन्।
नेपाल Telecom र Ncell दुवैका users affected भएका छन्।
HOTP/TOTP Standard: RFC 6238 Jargon-Free Explanation
TOTP = HOTP with Time Counter
# TOTP simply HOTP हो जहाँ counter = T
# T = floor((current_unix_time - T0) / X)
# T0 = Unix epoch (January 1, 1970 UTC) = 0
# X = time step = 30 seconds
# दुवै sides लाई थाहा छ:
# 1. Shared secret (setup मा एकपल्ट exchange भयो)
# 2. Current time (NTP बाट synchronized)
# त्यसैले दुवैले independently same T → same TOTP code compute गर्छन्।
RFC 6238 Parameters
| Parameter | RFC Default | Common Values |
|---|---|---|
| Hash algorithm | HMAC-SHA1 | SHA1, SHA256, SHA512 |
| Time step | 30 seconds | 30s (universal) |
| Code digits | 6 | 6 (universal), 8 (banks) |
| Secret length | ≥128 bits | 160 bits |
Secret Key Generation र Storage
import secrets, base64
# Cryptographically random 160-bit secret generate गर्नुहोस्
secret_bytes = secrets.token_bytes(20)
secret_b32 = base64.b32encode(secret_bytes).decode('utf-8')
# SECRET लाई PLAINTEXT मा DATABASE मा STORE नगर्नुहोस्
# AES-256-GCM वा KMS प्रयोग गर्नुहोस् (AWS KMS, HashiCorp Vault)
TOTP 2FA Setup: Major Platforms मा Step-by-Step
GitHub मा TOTP Setup
1. Settings → Password and authentication → Two-factor authentication
2. "Enable two-factor authentication" click गर्नुहोस्
3. "Authenticator app" select गर्नुहोस्
4. QR code scan गर्नुहोस् (Aegis/Raivo/Bitwarden बाट)
5. 6-digit code enter गरेर verify गर्नुहोस्
6. CRITICAL: 16 recovery codes download/copy गर्नुहोस्
- प्रत्येक code एकपल्ट मात्र use हुन्छ
- Password manager मा save गर्नुहोस् + printed copy
Node.js मा TOTP Implementation
import * as speakeasy from 'speakeasy';
import * as QRCode from 'qrcode';
// नयाँ user को लागि secret generate गर्नुहोस्
async function setupTOTP(userId: string, userEmail: string) {
const secret = speakeasy.generateSecret({
name: `MyApp (${userEmail})`,
issuer: 'MyApp',
length: 20,
});
const qrCode = await QRCode.toDataURL(secret.otpauth_url);
// Database मा ENCRYPTED secret store गर्नुहोस्
await db.users.update(userId, {
totpSecretEncrypted: await encryptSecret(secret.base32),
totpEnabled: false,
});
return { secret: secret.base32, qrCode };
}
// Login मा TOTP validate गर्नुहोस्
async function validateTOTP(userId: string, token: string) {
const user = await db.users.findById(userId);
const secret = await decryptSecret(user.totpSecretEncrypted);
return speakeasy.totp.verify({
secret, encoding: 'base32', token, window: 1
});
}
TOTP Device हरायो भने के गर्ने: Recovery Planning
Tier 1: Backup Codes (अनिवार्य छ)
Backup codes store गर्ने best practices:
✓ Password manager मा secure note मा
✓ Print गरेर physical safe मा
✓ Multiple geographic locations मा
कहिल्यै नगर्नुहोस्:
✗ Same device मा screenshot
✗ Email गरेर आफैंलाई
✗ Unencrypted notes मा
Backup code use गरेपछि:
1. Code बाट login गर्नुहोस्
2. TOTP disable गर्नुहोस्
3. नयाँ device मा re-enroll गर्नुहोस्
4. नयाँ backup codes generate र save गर्नुहोस्
Authenticator Apps Comparison
| App | Platform | Open Source | Cloud Backup | Export |
|---|---|---|---|---|
| Aegis | Android only | छ (GPL-3) | Self-managed encrypted | छ |
| Raivo OTP | iOS only | छ (MIT) | iCloud (E2E encrypted) | छ |
| Bitwarden | All platforms | छ (AGPL) | Bitwarden cloud | छ |
| Authy | All platforms | छैन | Authy cloud | छैन (lock-in!) |
TOTP का Security Risks: Phishing, SIM Swap र Mitigation
Attack 1: Real-Time Phishing (सबभन्दा खतरनाक)
Real-Time TOTP Relay Attack:
[User] → [Attacker को fake site] → [Real site]
1. User fake login page visit गर्छ
2. Username + password enter गर्छ
3. Attacker ले credentials real site लाई relay गर्छ
4. Real site: "2FA code enter गर्नुहोस्"
5. Fake site: "6-digit code enter गर्नुहोस्"
6. User TOTP code enter गर्छ
7. Attacker ले code seconds मा real site मा relay गर्छ
8. Attacker full session access पाउँछ
TOTP मा domain binding छैन — यही यसको limitation हो।
Passkeys (FIDO2) ले यो attack impossible बनाउँछ।
नेपालमा Phishing Attacks
Nepal Rastra Bank र CERT Nepal ले नेपाली banks र digital wallets (eSewa, Khalti, IME Pay) मा phishing attacks रिपोर्ट गरेका छन्। Real-time relay attacks sophisticated attackers गर्छन् — SMS OTP बाट TOTP मा upgrade गर्नु महत्वपूर्ण improvement हो, तर passkeys अझ राम्रो छन् जहाँ available छन्।
Attack 2: Device मा Malware
Device मा malware भए attacker:
1. Authenticator app को storage बाट TOTP secret read गर्न सक्छ
(rooted/jailbroken devices मा)
2. Screen/clipboard बाट TOTP code read गर्न सक्छ
Mitigation:
- Primary authenticator device root/jailbreak नगर्नुहोस्
- Biometric/PIN required app प्रयोग गर्नुहोस् (Aegis)
- Hardware security keys (device-level malware affected गर्दैन)
TOTP Best Practices: Backup Codes, Multiple Devices र App Recommendations
Individual Users को लागि Checklist
TOTP enable गर्नु अघि:
□ Authenticator app choose गर्नुहोस्
(Android: Aegis, iOS: Raivo, Cross-platform: Bitwarden)
□ Backup codes कहाँ store गर्ने decide गर्नुहोस्
□ Device loss को plan ready राख्नुहोस्
Setup को बेला:
□ Primary device मा QR scan गर्नुहोस्
□ Optional: secondary device मा पनि same QR scan गर्नुहोस्
□ Code verify गरेर setup finalize गर्नुहोस्
□ सबै backup codes तुरुन्त save गर्नुहोस्
□ Password manager + physical printed copy
Ongoing:
□ Backup codes update गर्नुहोस् (एउटा use भएपछि regenerate)
□ वार्षिक recovery test गर्नुहोस्
□ TOTP code SMS/email/phone call बाट share नगर्नुहोस् — fraud हो
Developers को लागि Implementation
// Rate limiting — brute force prevent गर्नुहोस्
const rateLimiter = rateLimit({
windowMs: 30 * 1000,
max: 3,
skipSuccessfulRequests: true,
});
// Token reuse prevention
async function markTokenUsed(userId: string, token: string, T: number) {
const key = `totp:used:${userId}:${T}:${token}`;
const existed = await redis.set(key, '1', 'EX', 90, 'NX');
if (!existed) throw new Error('Token already used');
}
// Timing-safe comparison
import { timingSafeEqual } from 'crypto';
function safeCompare(a: string, b: string): boolean {
const bufA = Buffer.from(a); const bufB = Buffer.from(b);
if (bufA.length !== bufB.length) return false;
return timingSafeEqual(bufA, bufB);
}
नेपाल IT Organizations को लागि Policy
Developer teams को लागि recommended:
□ Production access भएका सबै accounts मा TOTP mandatory गर्नुहोस्
(AWS, GitHub, GCP, Cloudflare)
□ SMS 2FA production system access को लागि कहिल्यै allow नगर्नुहोस्
□ Hardware keys (YubiKey) प्रयोग गर्नुहोस्:
- Domain registrar accounts
- DNS provider accounts
- Certificate authority accounts
□ Team password manager मा backup codes store गर्नुहोस्
□ Quarterly audit:
- कुन accounts मा 2FA enabled छ?
- कोही SMS 2FA प्रयोग गर्दैछ?
How to Use the Tool (Step by Step)
- 1
TOTP secret generate वा enter गर्नुहोस्
TOTP 2FA Generator बाट new random Base32 secret create गर्नुहोस्, वा existing secret enter गरेर test गर्नुहोस्। Tool ले default मा cryptographically secure 160-bit secret generate गर्छ।
- 2
QR code authenticator app बाट scan गर्नुहोस्
Aegis, Raivo, Bitwarden वा Google Authenticator बाट QR code scan गर्नुहोस्। App ले secret store गर्छ र 6-digit codes generate गर्न start गर्छ।
- 3
Current TOTP code verify गर्नुहोस्
Tool ले current 6-digit TOTP code र countdown timer show गर्छ। Verify गर्नुहोस् कि यो तपाईंको authenticator app सँग match गर्छ।
- 4
Time window note गर्नुहोस्
Validity window check गर्नुहोस् — code ३० seconds valid हुन्छ। Servers ले T-1 र T+1 पनि accept गर्छन्, effectively ९० seconds validity।
- 5
Different algorithms test गर्नुहोस्
Advanced users ले SHA-256 वा SHA-512, वा 8-digit codes test गर्न सक्छन्। Most services ले default SHA-1/6-digit configuration प्रयोग गर्छन्।
- 6
Backup codes save गर्नुहोस्
Real accounts मा TOTP enable गर्दा, service को backup codes तुरुन्त save गर्नुहोस्। Password manager मा store गर्नुहोस् र optionally print गर्नुहोस्।
Frequently Asked Questions
TOTP ले communicate नगरी दुवै sides मा same code कसरी generate गर्छ?+−
दुवै sides ले एउटै shared secret key share गर्छन् (setup मा QR code बाट exchange भयो) र current time थाहा छ। TOTP ले HMAC-SHA1(secret, floor(current_time / 30)) apply गर्छ एउटा deterministic code produce गर्न। Same inputs → same output — कुनै communication चाहिँदैन। यही TOTP को cryptographic magic हो: shared secret + synchronized clocks = synchronized codes।
TOTP 2026 मा safe छ? Passkeys प्रयोग गर्नुपर्छ?+−
TOTP password-only login भन्दा significantly बढी secure छ र SMS OTP भन्दा धेरै secure। तर TOTP phishing-resistant छैन — real-time relay attacks ले TOTP codes passwords सँगै चोर्न सक्छन्। Passkeys (FIDO2/WebAuthn) phishing-resistant छन् किनभने cryptographically domain-bound छन्। 2026 मा: passkeys जहाँ available छन् (Google, GitHub, Apple, Microsoft) प्रयोग गर्नुहोस्; अरू ठाउँमा TOTP। SMS OTP sensitive accounts को लागि कहिल्यै नप्रयोग गर्नुहोस्।
Phone को clock गलत भए के हुन्छ?+−
Phone को clock significantly गलत भए TOTP codes server को codes सँग match हुँदैन। Most servers ले T-1 र T+1 (±30 seconds) accept गर्छन् minor clock skew को लागि। 90 seconds भन्दा बढी off clock ले authentication failures cause गर्छ। Fix: device मा automatic time sync (NTP) enable गर्नुहोस्। Android: Settings → General management → Date and time → Automatic date and time ON।
TOTP codes brute-force हुन सक्छन्?+−
Theoretically, केवल 10 लाख (1,000,000) possible 6-digit codes छन्। तर servers ले rate limiting enforce गर्छन् — typically 3 attempts per 30-second window। त्यो rate मा average code brute-force गर्न हजारौं वर्ष लाग्छ। Plus account lockout after repeated failures। Proper server-side rate limiting सँग TOTP brute force practically infeasible छ।
Authy किन प्रयोग नगर्नु?+−
Authy का main drawbacks: (1) Export छैन — TOTP secrets Authy बाट export गर्न सकिँदैन। App switch गर्न सबै accounts manually re-enroll गर्नुपर्छ। (2) Proprietary closed-source backup। (3) Linux को लागि desktop app छैन। Alternatives: Aegis (Android, open source, fully exportable), Raivo (iOS, open source, iCloud E2E encrypted), Bitwarden (cross-platform, open source, full export/import)।
नेपालमा 2FA कहाँ-कहाँ enable गर्नु जरुरी छ?+−
Priority order: (1) Email account (Gmail/Outlook) — सबैभन्दा महत्वपूर्ण, यो compromise भए सबै password resets जान्छन्। (2) Domain registrar (Namecheap, GoDaddy) र DNS provider। (3) Cloud platforms (AWS, GCP, Azure) — financial impact ठूलो हुन सक्छ। (4) Code repositories (GitHub, GitLab). (5) Digital wallets (eSewa, Khalti) — यदि 2FA available छ। (6) Social media र professional accounts।
TOTP Codes अहिलेनै Generate र Test गर्नुहोस्
Secure TOTP secret generate गर्नुहोस्, QR code scan गर्नुहोस् र real-time 6-digit codes verify गर्नुहोस्। SHA-1, SHA-256, SHA-512 test गर्नुहोस्। निःशुल्क, server मा कुनै storage छैन।
TOTP 2FA Generator खोल्नुहोस्Related Guides
बलियो पासवर्ड बनाउनुहोस् — Nepal Cyber Security Guide 2026
eSewa, Khalti, FonePay account hack हुनबाट जोगाउनुस् — complete password guide।
Hash Generator — MD5, SHA-256 Nepali Guide (2026)
MD5, SHA-256 hashes generate गर्नुहोस् — hashing बुझ्नुहोस्, file verify गर्नुहोस्।
Base64 Encode/Decode गाइड
Base64 encoding र decoding — API development, data transmission, image embedding सबैका लागि।