Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/khurozov/totp
- Owner: khurozov
- License: mit
- Created: 2023-09-18T06:04:46.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-12T16:15:44.000Z (10 months ago)
- Last Synced: 2024-01-13T07:17:30.289Z (10 months ago)
- Topics: 2fa, google-authenticator, java, java-totp, totp, totp-codes, totp-generator, totp-java, totp-library
- Language: Java
- Homepage:
- Size: 23.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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).
## InstallationAdd maven dependency to your project
```xmluz.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.