It's pretty easy to add two-factor authentication to your cheetah app with e.g. Google Authenticator.

import { otp } from 'https://deno.land/x/cheetah/mod.ts'

Create a Secret

Generate a random secret (with a length of 64 by default).

const randomSecret = otp.secret(128) // with a length of 128

Retrieve a Token

Get the 6-digit token for a given timestamp (omit the timestamp to use the current time).

const token = otp.secret(secret, timestamp)

Create a URI

Create a URI that you can use, for example, for a QR code to scan with Google Authenticator.

//          otp.uri(label, issuer, secret)
const uri = otp.uri('[email protected]', 'My Company', secret)

Validate a Token

Determine if a given token is valid.

const isValid = otp.validate(token, secret)