Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pilcrowonpaper committed Dec 11, 2024
1 parent b0a98a0 commit b628fe4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions docs/pages/examples/totp.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ title: "Time-based one-time passwords"

# Time-based one-time passwords

Use [`generateTOTP()`](/reference/main/generateTOTP) and [`verifyTOTP()`](/reference/main/verifyTOTP) to generate and verify HOTPs.
Use [`generateTOTP()`](/reference/main/generateTOTP) to generate TOTPs and use [`verifyTOTPWithGracePeriod()`](/reference/main/verifyTOTPWithGracePeriod) or [`verifyTOTP()`](/reference/main/verifyTOTP) to verify them. Adding a grace period allows you to account for network latency and time discrepancy between devices.

```ts
import { generateTOTP, verifyTOTP } from "@oslojs/otp";
import { generateTOTP, verifyTOTPWithGracePeriod, verifyTOTP } from "@oslojs/otp";

const digits = 6;
const intervalInSeconds = 30;

const otp = generateTOTP(key, intervalInSeconds, digits);
const validOTP = verifyTOTP(key, intervalInSeconds, digits, otp);
const valid = verifyTOTPWithGracePeriod(key, intervalInSeconds, digits, otp, 30);
const valid = verifyTOTP(key, intervalInSeconds, digits, otp);
```

Use [`createTOTPKeyURI()`](/reference/main/createTOTPKeyURI) to create a key URI, which are then usually encoded into a QR code.
Expand Down
2 changes: 2 additions & 0 deletions docs/pages/reference/main/verifyTOTPWithGracePeriod.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: "verifyTOTPWithGracePeriod()"
---

# verifyTOTPWithGracePeriod()

Verifies a TOTP using [`verifyTOTP()`](/reference/main/verifyTOTP) with a grace period. If the grace period is 30 seconds for example, the OTP is valid if it was generated within the 30-second time span before or after the current machine time (60 seconds in total).

```ts
Expand Down

0 comments on commit b628fe4

Please sign in to comment.