Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/khurozov/totp

Java implementation of TOTP
https://github.com/khurozov/totp

2fa google-authenticator java java-totp totp totp-codes totp-generator totp-java totp-library

Last synced: 13 days ago
JSON representation

Java implementation of TOTP

Awesome Lists containing this project

README

        

# Java implementation of TOTP

TOTP (Time-based One-Time Password) algorithm is extension of HOTP (HMAC-based One-Time Password) and additional info can be more about it [here](https://datatracker.ietf.org/doc/html/rfc6238).

## Installation

Add maven dependency to your project
```xml

uz.khurozov
totp
1.0.2

```

## Defaults

- Algorithm: SHA1
- Digits: 6
- Period: 30 seconds

## Example

```java
import uz.khurozov.totp.*;

public class Demo {
public static void main(String[] args) {
// previously generated BASE32 secret
String secret = "6GCM7ZFJJGEMHIWZSPQRXV2B66EO7PUS";
System.out.println("secret: " + secret);

// TOTP instance can be created for a secret once
// and generate codes repeatedly
TOTP totp = new TOTP(secret);
for (int i = 0; i < 10; ++i) {
System.out.println(totp.getCode());

try {
Thread.sleep(totp.getPeriod());
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
```

## NOTES

Checked with Google Authenticator app and worked correctly.

Feel free to report about issues or contribute.