SimpleOTP 1.2.3

Suggested Alternatives

EugeneFox.SimpleOTP

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package SimpleOTP --version 1.2.3                
NuGet\Install-Package SimpleOTP -Version 1.2.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SimpleOTP" Version="1.2.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SimpleOTP --version 1.2.3                
#r "nuget: SimpleOTP, 1.2.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SimpleOTP as a Cake Addin
#addin nuget:?package=SimpleOTP&version=1.2.3

// Install SimpleOTP as a Cake Tool
#tool nuget:?package=SimpleOTP&version=1.2.3                

SimpleOTP

GitHub last commit MIT License

Twitter Follow GitHub followers Buy Me a Coffee

.NET library for TOTP/HOTP implementation on server (ASP.NET) or client (Xamarin) side

Features

  • Generate and validate OTP codes
  • Support of TOTP (RFC 6238) and HOTP (RFC 4226) algorithms
  • Support of HMAC-SHA1, HMAC-SHA256 and HMAC-SHA512 hashing algorithms
  • Setup URI parser
  • Database-ready configuration models
  • Configuration generator for server-side implementation
  • QR code generator
  • No dependencies

Usage

See more documentation at project's wiki

Generate code

string sample_config_uri = "otpauth://totp/FoxDev%20Studio:eugene@xfox111.net?secret=ESQVTYRM2CWZC3NX24GRRWIAUUWVHWQH&issuer=FoxDev%20Studio";
OTPConfiguration config = OTPConfiguration.GetConfiguration(sample_config_uri);
// OTPConfiguration { Id = af2358b0-3f69-4dd7-9537-32c07d6663aa, Type = TOTP, IssuerLabel = FoxDev Studio, AccountName = eugene@xfox111.net, Secret = ESQVTYRM2CWZC3NX24GRRWIAUUWVHWQH, Issuer = FoxDev Studio, Algorithm = SHA1, Digits = 6, Counter = 0, Period = 00:00:30 }


OTPCode code = OTPService.GenerateCode(ref config);
// OTPasswordModel { Code = 350386, Expiring = 23-May-21 06:08:30 PM }

Validate code

int codeToValidate = 350386;
bool isValid = OTPService.ValidateTotp(codeToValidate, config, TimeSpan.FromSeconds(30)); // True

Generate setup config

OTPConfiguration config = OTPConfiguration.GenerateConfiguration("FoxDev Studio", "eugene@xfox111.net");
// OTPModel { Id = af2358b0-3f69-4dd7-9537-32c07d6663aa, Type = TOTP, IssuerLabel = FoxDev Studio, AccountName = eugene@xfox111.net, Secret = ESQVTYRM2CWZC3NX24GRRWIAUUWVHWQH, Issuer = FoxDev Studio, Algorithm = SHA1, Digits = 6, Counter = 0, Period = 00:00:30 }

Uri uri = config.GetUri();	// otpauth://totp/FoxDev%20Studio:eugene@xfox111.net?secret=ESQVTYRM2CWZC3NX24GRRWIAUUWVHWQH&issuer=FoxDev%20Studio
string qrCode = config.GetQrImage(300); // data:image/png;base64,...

Streamline code generation for client

OTPFactory factory = new (config);

factory.CodeUpdated += (newCode) => Console.WriteLine(newCode);
// OTPCode { Code = 350386, Expiring = 23-May-21 06:08:30 PM }
factory.PropertyChanged += (sender, args) =>
{
	if (args.PropertyName == nameof(factory.TimeLeft))
		Console.WriteLine(factory.TimeLeft);
	else
		Console.WriteLine(factory.Code);
}
...
factory.Dispose();

Download

Nuget Nuget

CI/DC status

Build Status

Azure DevOps tests Azure DevOps coverage

Contributing

GitHub issues GitHub repo size

There are many ways in which you can participate in the project, for example:

If you are interested in fixing issues and contributing directly to the code base, please see the Contribution Guidelines, which covers the following:

Code of Conduct

This project has adopted the Contributor Covenant. For more information see the Code of Conduct

Copyrights

©2022 Eugene Fox

Licensed under MIT License

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net5.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated

- Fixed invalid code generation with secrets which are lowercase or space-separated