Otp.NET implements RFC 6238 TOTP and RFC 4226 HOTP in C# for generating and verifying one-time passwords used in two-factor authentication.
Overview
Otp.NET gives .NET applications a straightforward way to compute and validate time-based and counter-based one-time codes from a shared secret. The timed variant rolls codes over configurable step windows and supports SHA-1, SHA-256, and SHA-512 hashing with adjustable digit length.
Developers create Totp or Hotp instances, call compute methods with UTC timestamps or counters, and verify user-supplied codes. Verification can honor RFC-recommended clock skew via a verification window, report which time step matched, and apply optional time-correction offsets when client clocks drift from authoritative time.
Additional helpers generate OTP URI strings in the standard key URI format and provide Base32 encoding utilities compatible with authenticator apps. The package ships on NuGet for .NET Standard, modern .NET, and .NET Framework targets and can run server-side or inside mobile apps built with Mono.
Consumers remain responsible for ensuring each code is accepted only once, since the library itself does not persist usage state.
Key features
- RFC 6238 TOTP implementation
- RFC 4226 HOTP implementation
- Configurable hash and digit size
- VerifyTotp with skew windows
- TimeCorrection for clock drift
- OTP URI key format generator
- Base32 encoding helper
- NuGet distribution for .NET
Use cases
- Server-side 2FA verification
- Embedding OTP in mobile apps
- Building custom authenticator flows
- Generating provisioning URIs