1
0
mirror of https://github.com/XFox111/SimpleOTP.git synced 2026-04-22 08:00:45 +03:00
whitesource-bolt-for-github[bot] cfa2b02b80 Add .whitesource configuration file (#1)
Co-authored-by: whitesource-bolt-for-github[bot] <42819689+whitesource-bolt-for-github[bot]@users.noreply.github.com>
2021-05-28 18:37:45 +03:00
2021-05-28 18:36:54 +03:00
2021-05-28 18:36:54 +03:00
2021-05-28 18:36:54 +03:00
2021-05-23 16:14:41 +03:00
2021-05-28 18:36:54 +03:00
2021-05-28 18:36:54 +03:00
2021-05-23 16:14:41 +03:00
2021-05-28 18:36:54 +03:00
2021-05-28 18:36:54 +03:00

SimpleOTP

GitHub release (latest by date)

GitHub issues GitHub last commit GitHub repo size 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

By Mateusz Adamowski, taken with Canon EOS. - Own work, CC BY-SA 1.0, https://commons.wikimedia.org/w/index.php?curid=142232

By Mateusz Adamowski, taken with Canon EOS. - Own work, CC BY-SA 1.0, https://commons.wikimedia.org/w/index.php?curid=142232

Usage

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);
// 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 }

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.ValidateCode(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);
// OTPasswordModel { 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

Contributing

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

©2021 Michael "XFox" Gordeev

Licensed under MIT License

S
Description
Feature-rich and flexible .NET library for implementation of OTP authenticators and validatiors.
https://at.xfox111.net/simple-otp Readme MIT 259 KiB
Languages
C# 100%