Skip to content

A Custom OTP Library Supporting TOTP and HOTP for Google, Microsoft, and RFC 6238-Compatible Authentication Integration

License

Notifications You must be signed in to change notification settings

ogulcanturan/Ogu.Otp

Repository files navigation

Header Ogu.Otp

.NET NuGet Nuget

Introduction

This library offers support for both Time-Based One-Time Password (TOTP) and HMAC-based one-time password (HOTP) protocols, enabling secure and reliable authentication for various applications. With seamless integration for Google, Microsoft, and other RFC 6238-compliant authentication systems

Features

  • TOTP (MD5, SHA1, SHA256, SHA384, SHA512)
  • HOTP (MD5, SHA1, SHA256, SHA384, SHA512)
  • Includes Base32Helper class

Installation

You can install the library via NuGet Package Manager:

dotnet add package Ogu.Otp

Usage

Totp:

private static readonly TotpTokenProvider _totp = new TotpTokenProvider("MyAppName");

var secretKey = _totp.GenerateSecretKey(); // Save this for further evaluations

string uri = _totp.GetUri("Ogulcan", secretKey); // Needed for generating qr code

// (optional) manually you can generate code ( e.g time based email verification ) but this generally returns from Auth app (Google, Microsoft)
var code = _totp.GenerateCode(secretKey); 

var otpValidationResult = _totp.ValidateCode(code, secretKey); // validates the code and returns the validation result

Hotp:

private static readonly HotpTokenProvider _hotp = new HotpTokenProvider("MyAppName");

var secretKey = _hotp.GenerateSecretKey(); // Save this for further evaluations

string uri = _hotp.GetUri("Ogulcan", secretKey); // Needed for generating qr code

// (optional) manually you can generate code ( e.g time based email verification ) but this generally returns from Auth app (Google, Microsoft)
var code = _hotp.GenerateCode(secretKey);

long counter = 0;

var otpValidationResult = _hotp.ValidateCode(code, secretKey, counter);

if (otpValidationResult.IsValid)
{
    counter++; // increase the counter and save it to database
}

Sample Application

A sample application demonstrating the usage of Ogu.Otp Console, Otp.Api.

Credits

This library makes use of certain codes and resources from AspNetCore, Base32.cs, Rfc6238AuthenticationService.cs

About

A Custom OTP Library Supporting TOTP and HOTP for Google, Microsoft, and RFC 6238-Compatible Authentication Integration

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages