FoxSamu / otp

A simple One-Time Password verifier for Java, for two-factor authentication. Supports HOTP and TOTP.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

One-Time Password (OTP) generator and verifier for Java

This simple library can generate One-Time Passwords (OTPs) for 2-factor authentication systems, either time based or counter based.

Usage

To create a verifier, you'll need a secret key. A key can be obtained from a KeyGenerator and will be either a byte[] with the raw key or a Base-32 encoded string of the key.

OtpFactory factory = new OtpFactory();
// You can set various properties in the OtpFactory instance

Totp totp = factory.totp(yourSecretKey);

try {
    // To generate a code
    String code = totp.code();
    
    // To verify a code
    boolean verified = totp.verify(code);
} catch (OtpGenException exc) {
    // This checked exception wraps exceptions occurring during code generation
    exc.printStackTrace();
}

Installation

You can install the library from my maven: https://maven.shadew.net/.

repositories {
    maven { url "https://maven.shadew.net/" }
}

dependencies {
    implementation "net.shadew:otp:0.1"
}

About

A simple One-Time Password verifier for Java, for two-factor authentication. Supports HOTP and TOTP.


Languages

Language:Java 100.0%