2FA
2FA library compatible with google authenticator and authy
using System;
using TwoFactorAuthentication;
namespace Example
{
class Program
{
static void Main(string[] args)
{
//Generate 2FA code(Client)
var generator = new TwoFactor("SECRET");
Console.WriteLine(generator.GenerateCode());
//Get input from console.
string code;
do
Console.Write("Enter a generated 2FA code to check: ");
while ((code = Console.ReadLine()).Length != 6);
//Check 2FA code(Server)
Console.WriteLine(generator.ValidateCode(code)?"Code is valid.":"Code is invalid.");
Console.ReadLine();
//Generate new 2FA secret (static)
string secret = TwoFactor.GenerateSecret();
}
}
}