Skip to content
/ 2FA Public

Small 2FA library compatible with google authenticator and authy.

License

Notifications You must be signed in to change notification settings

Job79/2FA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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