<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Noben Nguyen</title>
    <description>The latest articles on DEV Community by Noben Nguyen (@noben_nguyen_bf5bc6c8dc7e).</description>
    <link>https://dev.to/noben_nguyen_bf5bc6c8dc7e</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4268483%2F83d973eb-7a24-4b4c-a75d-21329e771b36.jpg</url>
      <title>DEV Community: Noben Nguyen</title>
      <link>https://dev.to/noben_nguyen_bf5bc6c8dc7e</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/noben_nguyen_bf5bc6c8dc7e"/>
    <language>en</language>
    <item>
      <title>Writing numbers in Vietnamese words: the rules that break every number-to-words library</title>
      <dc:creator>Noben Nguyen</dc:creator>
      <pubDate>Fri, 27 Nov 2026 09:09:17 +0000</pubDate>
      <link>https://dev.to/noben_nguyen_bf5bc6c8dc7e/writing-numbers-in-vietnamese-words-the-rules-that-break-every-number-to-words-library-h4i</link>
      <guid>https://dev.to/noben_nguyen_bf5bc6c8dc7e/writing-numbers-in-vietnamese-words-the-rules-that-break-every-number-to-words-library-h4i</guid>
      <description>&lt;p&gt;If you've ever generated invoices for Vietnam, you've hit this requirement: the total must be written &lt;strong&gt;in numbers and in words&lt;/strong&gt;. &lt;code&gt;1.250.000 ₫&lt;/code&gt; has to become &lt;em&gt;Một triệu hai trăm năm mươi nghìn đồng&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Generic number-to-words libraries get Vietnamese wrong in at least five places. Here they are, with the code that handles them.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. A zero tens digit is read "linh" (or "lẻ")
&lt;/h2&gt;

&lt;p&gt;105 is not "một trăm năm" – that would mean 150 in casual speech. It's &lt;strong&gt;một trăm linh năm&lt;/strong&gt;. Southern speakers say &lt;em&gt;lẻ&lt;/em&gt;, so make it an option.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. "mười" vs "mươi"
&lt;/h2&gt;

&lt;p&gt;10–19 use &lt;em&gt;mười&lt;/em&gt; (ten). 20–99 use &lt;em&gt;mươi&lt;/em&gt; after the tens digit: 30 = &lt;em&gt;ba mươi&lt;/em&gt;. Same letters, different tone mark – and a different word.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. The units digit changes its name
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;1 after 20+ becomes &lt;strong&gt;mốt&lt;/strong&gt;: 21 = &lt;em&gt;hai mươi mốt&lt;/em&gt; (but 11 = &lt;em&gt;mười một&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;5 after any tens becomes &lt;strong&gt;lăm&lt;/strong&gt;: 15 = &lt;em&gt;mười lăm&lt;/em&gt;, 25 = &lt;em&gt;hai mươi lăm&lt;/em&gt; (but 105 = &lt;em&gt;một trăm linh năm&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;4 after 20+ is usually &lt;strong&gt;tư&lt;/strong&gt;: 24 = &lt;em&gt;hai mươi tư&lt;/em&gt; (but 14 = &lt;em&gt;mười bốn&lt;/em&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. "không trăm" in the middle
&lt;/h2&gt;

&lt;p&gt;1.005.000 is read &lt;strong&gt;một triệu không trăm linh năm nghìn&lt;/strong&gt;. Accountants want the explicit &lt;em&gt;không trăm&lt;/em&gt; (zero hundred) so nobody can alter the amount. Groups that are entirely zero are skipped, so 1.000.005 is just &lt;em&gt;một triệu không trăm linh năm&lt;/em&gt; – no "không nghìn".&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Billions nest
&lt;/h2&gt;

&lt;p&gt;There's no word for 10^12. 1.500 billion is &lt;em&gt;một nghìn năm trăm tỷ&lt;/em&gt; – "one thousand five hundred billion".&lt;/p&gt;

&lt;h2&gt;
  
  
  The core: reading one 3-digit group
&lt;/h2&gt;

&lt;p&gt;Everything above lives in one small function. &lt;code&gt;full&lt;/code&gt; means "this group is not the first one", so it must read &lt;em&gt;không trăm&lt;/em&gt; and &lt;em&gt;linh&lt;/em&gt; explicitly:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const D = ['không','một','hai','ba','bốn','năm','sáu','bảy','tám','chín'];

function readTriple(n, full) {               // n: 0..999
  const h = Math.floor(n / 100), t = Math.floor(n / 10) % 10, u = n % 10, w = [];
  if (h || full) w.push(D[h], 'trăm');
  if (t === 0 &amp;amp;&amp;amp; u &amp;amp;&amp;amp; (h || full)) w.push('linh');       // 105 → một trăm linh năm
  else if (t === 1) w.push('mười');
  else if (t &amp;gt; 1) w.push(D[t], 'mươi');
  if (u === 1 &amp;amp;&amp;amp; t &amp;gt; 1) w.push('mốt');                   // 21 → hai mươi mốt
  else if (u === 4 &amp;amp;&amp;amp; t &amp;gt; 1) w.push('tư');               // 24 → hai mươi tư
  else if (u === 5 &amp;amp;&amp;amp; t &amp;gt; 0) w.push('lăm');              // 15, 25 → mười lăm, hai mươi lăm
  else if (u) w.push(D[u]);
  return w;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Split the number into groups of three from the right, read each non-zero group, append &lt;em&gt;nghìn / triệu / tỷ&lt;/em&gt;, and you're 90% there. Use &lt;strong&gt;BigInt&lt;/strong&gt; or plain digit strings – invoice totals in VND overflow &lt;code&gt;Number.MAX_SAFE_INTEGER&lt;/code&gt; faster than you'd think once you hit 16 digits.&lt;/p&gt;

&lt;h2&gt;
  
  
  The other 10%: parsing what people type
&lt;/h2&gt;

&lt;p&gt;Vietnamese users type &lt;code&gt;1.250.000&lt;/code&gt;, &lt;code&gt;1,250,000&lt;/code&gt;, &lt;code&gt;1,25 triệu&lt;/code&gt;, &lt;code&gt;1tr250&lt;/code&gt;, &lt;code&gt;500k&lt;/code&gt;, &lt;code&gt;1 tỷ 250 triệu&lt;/code&gt;. A dot or comma before exactly three digits is a thousands separator; otherwise it's a decimal. That one rule resolves almost every ambiguity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Open source + a free tool
&lt;/h2&gt;

&lt;p&gt;I packaged all of this as &lt;strong&gt;&lt;a href="https://github.com/nguyennoben-a11y/doc-so-tien" rel="noopener noreferrer"&gt;doc-so-tien&lt;/a&gt;&lt;/strong&gt; (MIT, zero dependencies), including an English "amount in words" reader for VND/USD/EUR, an &lt;strong&gt;Excel VBA function &lt;code&gt;=DocSoTien(A1)&lt;/code&gt;&lt;/strong&gt; and a &lt;strong&gt;Google Sheets &lt;code&gt;=DOCSOTIEN(A1)&lt;/code&gt;&lt;/strong&gt;. The JS, VBA and Apps Script versions are cross-checked on 40,000+ numbers.&lt;/p&gt;

&lt;p&gt;If you just need the words, it runs at &lt;strong&gt;&lt;a href="https://docso.co" rel="noopener noreferrer"&gt;docso.co&lt;/a&gt;&lt;/strong&gt; – paste one number or a whole Excel column, everything computed in your browser.&lt;/p&gt;

&lt;p&gt;Found a reading I got wrong? Tell me in the comments.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>i18n</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Residential, mobile or datacenter? How to tell what proxy you actually bought</title>
      <dc:creator>Noben Nguyen</dc:creator>
      <pubDate>Fri, 27 Nov 2026 08:53:34 +0000</pubDate>
      <link>https://dev.to/noben_nguyen_bf5bc6c8dc7e/residential-mobile-or-datacenter-how-to-tell-what-proxy-you-actually-bought-2ol8</link>
      <guid>https://dev.to/noben_nguyen_bf5bc6c8dc7e/residential-mobile-or-datacenter-how-to-tell-what-proxy-you-actually-bought-2ol8</guid>
      <description>&lt;p&gt;If you run multiple accounts, scrape, or test geo-targeted ads, you have probably bought "residential" proxies that behaved suspiciously like a server rack. Here is how to check what you actually got — the same logic I use in a free bulk checker I built.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Parse the list first
&lt;/h2&gt;

&lt;p&gt;Sellers ship lists as &lt;code&gt;ip:port:user:pass&lt;/code&gt;, &lt;code&gt;user:pass@ip:port&lt;/code&gt;, &lt;code&gt;user:pass:ip:port&lt;/code&gt;, &lt;code&gt;socks5://…&lt;/code&gt;, pipes, spaces… Half of "dead proxy" reports are really a parsing problem: the user and password ended up in the host field.&lt;/p&gt;

&lt;p&gt;I open-sourced the parser I use (zero dependencies, MIT): &lt;strong&gt;&lt;a href="https://github.com/nguyennoben-a11y/proxy-line-parser" rel="noopener noreferrer"&gt;github.com/nguyennoben-a11y/proxy-line-parser&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { parseList, convert } = require('proxy-line-parser');&lt;br&gt;
const { ok, bad, dupes } = parseList(text);      // any format in&lt;br&gt;
convert(text, 'gologin', { type: 'socks5' });   // GoLogin / AdsPower / Dolphin out&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  

&lt;ol&gt;
&lt;li&gt;Look at the exit IP, not the entry IP
&lt;/li&gt;
&lt;/ol&gt;
&lt;/h2&gt;


&lt;p&gt;The host you connect to is often a gateway. What websites see is the &lt;strong&gt;exit IP&lt;/strong&gt;. Connect through the proxy and ask an "echo my IP" endpoint — that IP is the one that matters for everything below.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Residential vs datacenter: check the ASN
&lt;/h2&gt;

&lt;p&gt;Every IP belongs to an Autonomous System (ASN) — the network that announces it. That is the most reliable cheap signal:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Datacenter:&lt;/strong&gt; the ASN belongs to a hosting company — AWS, Google Cloud, OVH, Hetzner, DigitalOcean, M247, Leaseweb…&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mobile:&lt;/strong&gt; the ASN belongs to a mobile carrier (Viettel, T-Mobile, Vodafone…), and many users share the same IP behind carrier-grade NAT.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Residential / ISP:&lt;/strong&gt; the ASN belongs to a home broadband provider.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is an estimate, not proof: some ISPs also sell hosting, and "ISP proxies" are datacenter servers announced under an ISP's ASN. But if a "residential" proxy exits from a hosting ASN, you did not get what you paid for.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Sticky or rotating?
&lt;/h2&gt;

&lt;p&gt;Send 10 requests through the same proxy a few seconds apart and record the exit IP each time. One IP = sticky session. A new IP on every request = rotating. A mix usually means the session expired — check the seller's session parameter.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Why a proxy shows "dead" but works in your browser
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Wrong format&lt;/strong&gt; (see step 1).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IP whitelist:&lt;/strong&gt; the seller only allows your home IP, so any other machine is refused.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Protocol mismatch:&lt;/strong&gt; testing a SOCKS5 port as HTTP fails instantly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The target blocks it:&lt;/strong&gt; the proxy is alive, but a specific site refuses its IP. Test the connection to the sites you actually use, not only an IP-echo endpoint.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A free tool that does all of this
&lt;/h2&gt;

&lt;p&gt;I packaged these checks into &lt;strong&gt;&lt;a href="https://checkproxy.co" rel="noopener noreferrer"&gt;CheckProxy&lt;/a&gt;&lt;/strong&gt;: paste up to 300 HTTP/SOCKS5 proxies, see alive/dead, speed, exit IP, country and ISP, then open a report per proxy with the network-type estimate, Tor check, rotation test and site-connection test. It exports working proxies straight to GoLogin, AdsPower, Dolphin, MoreLogin and Hidemium. Free, no sign-up, proxies are not stored.&lt;/p&gt;

&lt;p&gt;What other proxy checks do you run before trusting a list? Happy to add them.&lt;/p&gt;

</description>
      <category>networking</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How 2FA (TOTP) codes actually work – and why your code is "wrong"</title>
      <dc:creator>Noben Nguyen</dc:creator>
      <pubDate>Fri, 27 Nov 2026 08:46:25 +0000</pubDate>
      <link>https://dev.to/noben_nguyen_bf5bc6c8dc7e/how-2fa-totp-codes-actually-work-and-why-your-code-is-wrong-jl0</link>
      <guid>https://dev.to/noben_nguyen_bf5bc6c8dc7e/how-2fa-totp-codes-actually-work-and-why-your-code-is-wrong-jl0</guid>
      <description>&lt;p&gt;Every time you type a 6-digit code from Google Authenticator, you're using &lt;strong&gt;TOTP&lt;/strong&gt; – Time-based One-Time Passwords (RFC 6238). It's a surprisingly small algorithm, and once you see it, a lot of "my 2FA code doesn't work" problems make sense.&lt;/p&gt;

&lt;h2&gt;
  
  
  The shared secret
&lt;/h2&gt;

&lt;p&gt;When you enable 2FA, the service shows a QR code. Inside is a URI like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;otpauth://totp/GitHub:me?secret=JBSWY3DPEHPK3PXP&amp;amp;issuer=GitHub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;JBSWY3DPEHPK3PXP&lt;/code&gt; is the secret, Base32-encoded. The service keeps a copy; your app keeps a copy. That's the whole "enrollment".&lt;/p&gt;

&lt;h2&gt;
  
  
  The algorithm in 10 lines
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Take the current Unix time and divide by 30 → a counter that changes every 30 seconds.&lt;/li&gt;
&lt;li&gt;HMAC-SHA1 the counter (8 bytes, big-endian) with the secret.&lt;/li&gt;
&lt;li&gt;Pick 4 bytes from the result using the last nibble as an offset ("dynamic truncation").&lt;/li&gt;
&lt;li&gt;Take that number mod 10^6 → your 6-digit code.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the browser, with zero dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;totp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;secretBytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;period&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;digits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;period&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ArrayBuffer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DataView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setUint32&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;           &lt;span class="c1"&gt;// fine until year 2106&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subtle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;importKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'raw'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;secretBytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'HMAC'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'SHA-1'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'sign'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Uint8Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subtle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sign&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'HMAC'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;bin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mh"&gt;0x7f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="n"&gt;digits&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;padStart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;digits&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'0'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same secret + same time = same code, on any device. No network needed.&lt;/p&gt;

&lt;h2&gt;
  
  
  So why is my code "wrong"?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Clock drift.&lt;/strong&gt; The counter comes from &lt;em&gt;your&lt;/em&gt; device clock. If it's 30+ seconds off, you're computing the previous or next code. Most servers accept ±1 step, so a minute of drift breaks it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Wrong parameters.&lt;/strong&gt; Some services use SHA256, 8 digits or a 60-second period. The QR code says so; a manually typed key doesn't.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Typos in the key.&lt;/strong&gt; Base32 has no 0, 1 or 8. An "O" vs "0" mix-up gives a valid-looking but wrong secret.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Steam&lt;/strong&gt; uses its own 5-character alphabet on top of the same HOTP value.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A tool if you just need the codes
&lt;/h2&gt;

&lt;p&gt;I packaged this into &lt;strong&gt;&lt;a href="https://code2fa.co" rel="noopener noreferrer"&gt;Code2FA&lt;/a&gt;&lt;/strong&gt;: paste a key (or hundreds of &lt;code&gt;ID|Pass|2FA&lt;/code&gt; lines) or scan a QR code, and it shows live codes – computed in your browser, keys never uploaded. It also reads Google Authenticator export QR codes and has a "why is my code rejected?" checker that measures your clock.&lt;/p&gt;

&lt;p&gt;The engine is open source (MIT, ~10 KB, all RFC 6238 test vectors pass): &lt;strong&gt;&lt;a href="https://github.com/nguyennoben-a11y/code2fa-totp" rel="noopener noreferrer"&gt;github.com/nguyennoben-a11y/code2fa-totp&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Questions about TOTP edge cases? Ask in the comments.&lt;/p&gt;

</description>
      <category>security</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
