Skip to content

Instantly share code, notes, and snippets.

@iamazeem
Created January 1, 2025 08:18
Show Gist options
  • Select an option

  • Save iamazeem/2daf06dc4c2ae91e010e60200c0e6e76 to your computer and use it in GitHub Desktop.

Select an option

Save iamazeem/2daf06dc4c2ae91e010e60200c0e6e76 to your computer and use it in GitHub Desktop.
otplib-demo (TOTP)
<!DOCTYPE html>
<html>
<head>
<title>otplib demo</title>
<script src="https://unpkg.com/@otplib/preset-browser@^12.0.0/buffer.js"></script>
<script src="https://unpkg.com/@otplib/preset-browser@^12.0.0/index.js"></script>
<script type="text/javascript">
const authenticator = window.otplib.authenticator;
authenticator.options = { window: 1 };
const secret = authenticator.generateSecret();
const token = authenticator.generate(secret);
const verify = authenticator.verify({ token, secret });
console.log(secret, token, verify);
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment