---
title: "TOTP.verify(code, [timeStep]) | Grafana k6 documentation"
description: "Verify a TOTP code"
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# TOTP.verify(code, \[timeStep])

Verifies a TOTP code against the current time.

Expand table

| Parameter           | Type   | Description                        |
|---------------------|--------|------------------------------------|
| code                | string | The TOTP code to verify            |
| timeStep (optional) | number | Time step in seconds (default: 30) |

### Returns

Expand table

| Type    | Description                                    |
|---------|------------------------------------------------|
| Promise | `true` if the code is valid, `false` otherwise |

### Example

JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```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!');
  }
}
```
