Skip to content
/ ezauth Public

Dead simple user authentication for C# with support for 2FA via TOTP

Notifications You must be signed in to change notification settings

aechan/ezauth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

NuGet version

ezauth

Dead simple user authentication for C# with support for 2FA.

Usage

  • Add reference to ezauth.lib project.

  • Or install via Nuget Install-Package ezauth.lib

    TOTP Example

    TOTP - Time-based One-Time Password is an algorithm that generates a one-time password based on a secret key and the current time.

    Defined in IETF RFC 6238, TOTP is usually used as a second factor in a 2FA setup.

    Users will need to have a TOTP client like Google Authenticator.

    Code Example

    using ezauth.lib.AuthProviders;
    
    // init new totp provider
    TOTPProvider totp = new TOTPProvider("ezauth_totp_test");
    
    // get the otp uri for sharing the secret with
    // a client e.g. Google Authenticator
    // Usually you'll encode this into a QR code (try QRCoder)
    string URI = totp.GetOTPURI();
    
    // validate the code given by the user for authentication
    AuthorizationData res = totp.Validate(user.username, input);
    
    // get the result of the Validate operation
    if (res.Result == AuthResult.VALIDATED) {
        Console.WriteLine("Your code was valid!");
        string token = res.AuthToken; // your JWT token for login later
    
    } else if (res.Result == AuthResult.INVALID_PASSCODE) {
        Console.WriteLine("Invalid code.");
    }

About

Dead simple user authentication for C# with support for 2FA via TOTP

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages