Skip to content

2 Factor Authentication system using Google Authenticator app in Java

License

Notifications You must be signed in to change notification settings

devpedrobarbosa/j-2fa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

j-2fa

Java-based 2FA system using Google Auth

Usage example:

public static void main(String[] args) {
        // Instantiate J2FA
        final J2FA authenticator = new J2FA("Example App");
        
        // Generate a new Secret Key for each new user
        final String secret = authenticator.generateSecret();
        System.out.println("Welcome, new user!\nYour Secret Key: " + secret + "\nAdd it in your Google Authenticator app to get a Token.");
        authenticator.createQRCodeFile(secret, new File("C:/J2FA/qrcode.png").getPath());
        
        // This key should be stored in a database within the user, for future authentications
        System.out.println("Current app Token: ");
        final String token = new Scanner(System.in).nextLine();
        if(authenticator.authenticate(token, secret))
            System.out.println("Access granted!");
        else System.out.println("Access denied. Invalid token.");
}

(can be found at ./src/main/java/me/pedrao/j2fa/example/ExampleApp.java)

About

2 Factor Authentication system using Google Authenticator app in Java

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages