<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>totp on Grafana Labs</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/totp/</link><description>Recent content in totp on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/k6/v2.3.x/javascript-api/jslib/totp/index.xml" rel="self" type="application/rss+xml"/><item><title>TOTP(secret, [digits])</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/totp/totp/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/totp/totp/</guid><content><![CDATA[&lt;h1 id=&#34;totpsecret-digits&#34;&gt;TOTP(secret, [digits])&lt;/h1&gt;
&lt;p&gt;Creates a new TOTP (Time-based One-Time Password) instance with the given secret.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Parameter&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;secret&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;Base32 encoded secret key&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;digits (optional)&lt;/td&gt;
              &lt;td&gt;number&lt;/td&gt;
              &lt;td&gt;Number of digits in the generated code (default: 6)&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;returns&#34;&gt;Returns&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;TOTP&lt;/td&gt;
              &lt;td&gt;A new TOTP object&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;example&#34;&gt;Example&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { TOTP } from &amp;#39;https://jslib.k6.io/totp/1.0.0/index.js&amp;#39;;

export default async function () {
  // Create a TOTP instance with 6 digits (default)
  const totp6 = new TOTP(&amp;#39;GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&amp;#39;);

  // Create a TOTP instance with 8 digits
  const totp8 = new TOTP(&amp;#39;GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&amp;#39;, 8);

  const code = await totp6.gen();
  console.log(`6-digit TOTP: ${code}`);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="totpsecret-digits">TOTP(secret, [digits])&lt;/h1>
&lt;p>Creates a new TOTP (Time-based One-Time Password) instance with the given secret.&lt;/p>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Parameter&lt;/th>
&lt;th>Type&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>secret&lt;/td>
&lt;td>string&lt;/td>
&lt;td>Base32 encoded secret key&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>digits (optional)&lt;/td>
&lt;td>number&lt;/td>
&lt;td>Number of digits in the generated code (default: 6)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h3 id="returns">Returns&lt;/h3>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Type&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>TOTP&lt;/td>
&lt;td>A new TOTP object&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h3 id="example">Example&lt;/h3>
&lt;div class="code-snippet ">&lt;div class="lang-toolbar">
&lt;span class="lang-toolbar__item lang-toolbar__item-active">JavaScript&lt;/span>
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;div class="lang-toolbar__border">&lt;/div>
&lt;/div>&lt;div class="code-snippet ">
&lt;pre data-expanded="false">&lt;code class="language-javascript">import { TOTP } from &amp;#39;https://jslib.k6.io/totp/1.0.0/index.js&amp;#39;;
export default async function () {
// Create a TOTP instance with 6 digits (default)
const totp6 = new TOTP(&amp;#39;GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&amp;#39;);
// Create a TOTP instance with 8 digits
const totp8 = new TOTP(&amp;#39;GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&amp;#39;, 8);
const code = await totp6.gen();
console.log(`6-digit TOTP: ${code}`);
}&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div></description></item><item><title>TOTP.gen([timeStep], [bias])</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/totp/gen/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/totp/gen/</guid><content><![CDATA[&lt;h1 id=&#34;totpgentimestep-bias&#34;&gt;TOTP.gen([timeStep], [bias])&lt;/h1&gt;
&lt;p&gt;Generates a TOTP code for the current time.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Parameter&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;timeStep (optional)&lt;/td&gt;
              &lt;td&gt;number&lt;/td&gt;
              &lt;td&gt;Time step in seconds (default: 30)&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;bias (optional)&lt;/td&gt;
              &lt;td&gt;number&lt;/td&gt;
              &lt;td&gt;Time bias in seconds to offset the current time (default: 0)&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;returns&#34;&gt;Returns&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Promise&lt;string&gt;&lt;/td&gt;
              &lt;td&gt;The generated TOTP code&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;example&#34;&gt;Example&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { TOTP } from &amp;#39;https://jslib.k6.io/totp/1.0.0/index.js&amp;#39;;

export default async function () {
  const totp = new TOTP(&amp;#39;GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&amp;#39;, 6);

  // Generate code with default 30-second time step
  const code = await totp.gen();
  console.log(`TOTP code: ${code}`);

  // Generate code with 60-second time step
  const code60 = await totp.gen(60);
  console.log(`TOTP code (60s step): ${code60}`);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="totpgentimestep-bias">TOTP.gen([timeStep], [bias])&lt;/h1>
&lt;p>Generates a TOTP code for the current time.&lt;/p>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Parameter&lt;/th>
&lt;th>Type&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>timeStep (optional)&lt;/td>
&lt;td>number&lt;/td>
&lt;td>Time step in seconds (default: 30)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>bias (optional)&lt;/td>
&lt;td>number&lt;/td>
&lt;td>Time bias in seconds to offset the current time (default: 0)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h3 id="returns">Returns&lt;/h3>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Type&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Promise&lt;string>&lt;/td>
&lt;td>The generated TOTP code&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h3 id="example">Example&lt;/h3>
&lt;div class="code-snippet ">&lt;div class="lang-toolbar">
&lt;span class="lang-toolbar__item lang-toolbar__item-active">JavaScript&lt;/span>
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;div class="lang-toolbar__border">&lt;/div>
&lt;/div>&lt;div class="code-snippet ">
&lt;pre data-expanded="false">&lt;code class="language-javascript">import { TOTP } from &amp;#39;https://jslib.k6.io/totp/1.0.0/index.js&amp;#39;;
export default async function () {
const totp = new TOTP(&amp;#39;GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&amp;#39;, 6);
// Generate code with default 30-second time step
const code = await totp.gen();
console.log(`TOTP code: ${code}`);
// Generate code with 60-second time step
const code60 = await totp.gen(60);
console.log(`TOTP code (60s step): ${code60}`);
}&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div></description></item><item><title>TOTP.verify(code, [timeStep])</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/totp/verify/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/totp/verify/</guid><content><![CDATA[&lt;h1 id=&#34;totpverifycode-timestep&#34;&gt;TOTP.verify(code, [timeStep])&lt;/h1&gt;
&lt;p&gt;Verifies a TOTP code against the current time.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Parameter&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;code&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;The TOTP code to verify&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;timeStep (optional)&lt;/td&gt;
              &lt;td&gt;number&lt;/td&gt;
              &lt;td&gt;Time step in seconds (default: 30)&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;returns&#34;&gt;Returns&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Promise&lt;boolean&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;true&lt;/code&gt; if the code is valid, &lt;code&gt;false&lt;/code&gt; otherwise&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;example&#34;&gt;Example&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { TOTP } from &amp;#39;https://jslib.k6.io/totp/1.0.0/index.js&amp;#39;;

export default async function () {
  const totp = new TOTP(&amp;#39;GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&amp;#39;, 6);

  // Generate and verify a code
  const code = await totp.gen();
  const isValid = await totp.verify(code);

  if (isValid) {
    console.log(&amp;#39;Code is valid!&amp;#39;);
  } else {
    console.log(&amp;#39;Code is invalid!&amp;#39;);
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="totpverifycode-timestep">TOTP.verify(code, [timeStep])&lt;/h1>
&lt;p>Verifies a TOTP code against the current time.&lt;/p>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Parameter&lt;/th>
&lt;th>Type&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>code&lt;/td>
&lt;td>string&lt;/td>
&lt;td>The TOTP code to verify&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>timeStep (optional)&lt;/td>
&lt;td>number&lt;/td>
&lt;td>Time step in seconds (default: 30)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h3 id="returns">Returns&lt;/h3>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Type&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Promise&lt;boolean>&lt;/td>
&lt;td>&lt;code>true&lt;/code> if the code is valid, &lt;code>false&lt;/code> otherwise&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h3 id="example">Example&lt;/h3>
&lt;div class="code-snippet ">&lt;div class="lang-toolbar">
&lt;span class="lang-toolbar__item lang-toolbar__item-active">JavaScript&lt;/span>
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;div class="lang-toolbar__border">&lt;/div>
&lt;/div>&lt;div class="code-snippet ">
&lt;pre data-expanded="false">&lt;code class="language-javascript">import { TOTP } from &amp;#39;https://jslib.k6.io/totp/1.0.0/index.js&amp;#39;;
export default async function () {
const totp = new TOTP(&amp;#39;GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&amp;#39;, 6);
// Generate and verify a code
const code = await totp.gen();
const isValid = await totp.verify(code);
if (isValid) {
console.log(&amp;#39;Code is valid!&amp;#39;);
} else {
console.log(&amp;#39;Code is invalid!&amp;#39;);
}
}&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div></description></item></channel></rss>