-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1630cd2
Showing
5 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
############################## | ||
## Java | ||
############################## | ||
.mtj.tmp/ | ||
*.class | ||
*.jar | ||
*.war | ||
*.ear | ||
*.nar | ||
hs_err_pid* | ||
replay_pid* | ||
|
||
############################## | ||
## Maven | ||
############################## | ||
target/ | ||
pom.xml.tag | ||
pom.xml.releaseBackup | ||
pom.xml.versionsBackup | ||
pom.xml.next | ||
pom.xml.bak | ||
release.properties | ||
dependency-reduced-pom.xml | ||
buildNumber.properties | ||
.mvn/timing.properties | ||
.mvn/wrapper/maven-wrapper.jar | ||
|
||
############################## | ||
## IntelliJ | ||
############################## | ||
out/ | ||
.idea/ | ||
.idea_modules/ | ||
*.iml | ||
*.ipr | ||
*.iws | ||
|
||
############################## | ||
## Eclipse | ||
############################## | ||
.settings/ | ||
bin/ | ||
tmp/ | ||
.metadata | ||
.classpath | ||
.project | ||
*.tmp | ||
*.bak | ||
*.swp | ||
*~.nib | ||
local.properties | ||
.loadpath | ||
.factorypath | ||
|
||
############################## | ||
## NetBeans | ||
############################## | ||
nbproject/private/ | ||
build/ | ||
nbbuild/ | ||
dist/ | ||
nbdist/ | ||
nbactions.xml | ||
nb-configuration.xml | ||
|
||
############################## | ||
## Visual Studio Code | ||
############################## | ||
.vscode/ | ||
.code-workspace | ||
|
||
############################## | ||
## OS X | ||
############################## | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# WHAT? | ||
Get the preconfigured OTP automatically in just 1 click, the OTP will be copied automatically, and you can paste on your application easily. | ||
|
||
You no longer have to: | ||
- Copy and paste your secret key, open a totp page on web browser, generate am OTP, copy and paste the generated OTP onto your application | ||
- Open your favourite password manager application, click to generate OTP, copy and paste the generated OTP onto your application | ||
|
||
# Prerequisite | ||
You will need to have your secret key associated with your account before running this tool | ||
|
||
# HOW TO? | ||
|
||
Configure the secret: | ||
Use either the following method: | ||
- Open secret file and update your secret string as the file content | ||
- Edit the GetOTP.cmd file and add the secret string to the command as the parameter. See **Run the project** section below. | ||
|
||
Build the project: | ||
|
||
```bash | ||
mvn package | ||
``` | ||
|
||
Run the project with terminal: | ||
|
||
```bash | ||
java -jar target/otp-generator-1.0-SNAPSHOT-jar-with-dependencies.jar | ||
``` | ||
|
||
Quick run the project: Update the **GetOTP.cmd** file with following content: | ||
```bash | ||
java -jar target/otp-generator-1.0-SNAPSHOT-jar-with-dependencies.jar | ||
``` | ||
|
||
Quick run the project with customized secret string: Update the **GetOTP.cmd** file with following content, and replace the sample secret string with your secret string: | ||
```bash | ||
java -jar target/otp-generator-1.0-SNAPSHOT-jar-with-dependencies.jar JBSWY3DPEHPK3PXPJBSWY3DPEHPK3PXP | ||
``` | ||
|
||
Attach the command above into a Batch or Command file. Single click onto the command file will get the OTP automatically. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.thanhhoang</groupId> | ||
<artifactId>otp-generator</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.j256.two-factor-auth</groupId> | ||
<artifactId>two-factor-auth</artifactId> | ||
<version>1.3</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<version>3.6.0</version> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<mainClass> | ||
com.thanhhoang.OTPGenerator | ||
</mainClass> | ||
</manifest> | ||
</archive> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
</configuration> | ||
|
||
<executions> | ||
<execution> | ||
<id>all</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
JBSWY3DPEHPK3PXPJBSWY3DPEHPK3PXP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.thanhhoang; | ||
|
||
import com.j256.twofactorauth.TimeBasedOneTimePasswordUtil; | ||
|
||
import java.awt.*; | ||
import java.awt.datatransfer.Clipboard; | ||
import java.awt.datatransfer.StringSelection; | ||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.security.GeneralSecurityException; | ||
import java.util.Scanner; | ||
|
||
public class OTPGenerator { | ||
private static String secret; | ||
public static void main(String... args) throws GeneralSecurityException { | ||
try { | ||
File myObj = new File("secret.txt"); | ||
Scanner myReader = new Scanner(myObj); | ||
// Read the first line only | ||
if (myReader.hasNextLine()) { | ||
secret = myReader.nextLine(); | ||
System.out.println(secret); | ||
} | ||
myReader.close(); | ||
} catch (FileNotFoundException e) { | ||
System.out.println("An error occurred."); | ||
e.printStackTrace(); | ||
} | ||
String otp = TimeBasedOneTimePasswordUtil.generateCurrentNumberString(args.length == 0 ? secret : args[0]); | ||
System.out.println("OTP Code generated: " + otp); | ||
StringSelection stringSelection = new StringSelection(otp); | ||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); | ||
clipboard.setContents(stringSelection, null); | ||
} | ||
} |