/UdonOTPLib

VRChat Udon OTP Library. contains a simple time-based one-time password example.

Primary LanguageC#MIT LicenseMIT

UdonOTPLib

VRChat Udon OTP Library, HOTP(RFC 4226) & TOTP(RFC 6238).

Caution

This project is a personal learning exercise and serves as a demonstration of my learning outcomes. It is not intended for production environments or serious business applications. Use the code in this project at your own risk.

Demo world

👇 Example video

thumbnail

Requirements

  • Unity 2022.3.6f1
  • VRChat SDK - Worlds (Tested version: 3.5.2)

How to use

Contains a simple example that you can use however you want.

  1. Make sure you have imported the latest VRChat SDK - Worlds.
  2. Download the latest release and import it into your project.
  3. Open the _Gizmo/UdonOTPLib/Example/TOTP_Example.unity scene.
  4. You may need to import TextMeshPro.
  5. Edit the Secret variable in the TOTP_Example gameobject. (You can use totp-wasm.vercel.app to generate Secret)
  6. enjoy 🤓

Parameter

Name Type Description
secret string Secret key encoded in base32
digits int Code digits
period int Time period (seconds)
t double Timestamp

Code example

string secret = "2LESRALCTRW3B3J4WYSXFQYE5ZR6V5R2";
int digits = 6;
int period = 30;

// Get the code
string code = otp.TOTP(secret, otp.Timestamp(), digits, period);
Debug.Log($"Code: {code}");

// Countdown
int s = otp.Countdown(period);
Debug.Log($"Countdown: {s}sec");

Related

License

Code is distributed under MIT license, feel free to use it in your proprietary projects as well.