Documentationbreadcrumb arrow Grafana k6breadcrumb arrow JavaScript APIbreadcrumb arrow jslibbreadcrumb arrow totpbreadcrumb arrow TOTP.verify(code, [timeStep])
Open source

TOTP.verify(code, [timeStep])

Verifies a TOTP code against the current time.

ParameterTypeDescription
codestringThe TOTP code to verify
timeStep (optional)numberTime step in seconds (default: 30)

Returns

TypeDescription
Promisetrue if the code is valid, false otherwise

Example

JavaScript
JavaScript
import { TOTP } from 'https://jslib.k6.io/totp/1.0.0/index.js';

export default async function () {
  const totp = new TOTP('GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ', 6);

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

  if (isValid) {
    console.log('Code is valid!');
  } else {
    console.log('Code is invalid!');
  }
}