Skip to content

Commit

Permalink
Initilise project
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanthanhvc committed Jul 9, 2023
0 parents commit 1630cd2
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 0 deletions.
75 changes: 75 additions & 0 deletions .gitignore
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
40 changes: 40 additions & 0 deletions README.md
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.
55 changes: 55 additions & 0 deletions pom.xml
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>
1 change: 1 addition & 0 deletions secret.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
JBSWY3DPEHPK3PXPJBSWY3DPEHPK3PXP
35 changes: 35 additions & 0 deletions src/main/java/com/thanhhoang/OTPGenerator.java
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);
}
}

0 comments on commit 1630cd2

Please sign in to comment.