@@ -0,0 +1,1353 @@
+package com.j256.common.utils;%0A%0A/**%0A * Little test program to show how to use the utility class.%0A */%0Apublic class TwoFactorAuthUtilTest %7B%0A%0A%09public static void main(String%5B%5D args) throws Exception %7B%0A%09%09new TwoFactorAuthUtilTest().doMain();%0A%09%7D%0A%0A%09private void doMain() throws Exception %7B%0A%0A%09%09TwoFactorAuthUtil twoFactorAuthUtil = new TwoFactorAuthUtil();%0A%0A%09%09// String base32Secret = generateBase32Secret();%0A%09%09String base32Secret = %22NY4A5CPJZ46LXZCP%22;%0A%0A%09%09System.out.println(%22secret = %22 + base32Secret);%0A%0A%09%09// this is the name of the key which can be displayed by the authenticator program%0A%09%09String keyId = %22user@foo.com%22;%0A%09%09System.out.println(%22Image url = %22 + twoFactorAuthUtil.qrImageUrl(keyId, base32Secret));%0A%09%09// we can display this image to the user to let them load it into their auth program%0A%0A%09%09// we can use the code here and compare it against user input%0A%09%09String code = twoFactorAuthUtil.generateCurrentNumber(base32Secret);%0A%0A%09%09/*%0A%09%09 * this little loop is here to show how the number changes over time%0A%09%09 */%0A%09%09while (true) %7B%0A%09%09%09long diff =%0A%09%09%09%09%09TwoFactorAuthUtil.TIME_STEP_SECONDS%0A%09%09%09%09%09%09%09- ((System.currentTimeMillis() / 1000) %25 TwoFactorAuthUtil.TIME_STEP_SECONDS);%0A%09%09%09code = twoFactorAuthUtil.generateCurrentNumber(base32Secret);%0A%09%09%09System.out.println(%22Secret code = %22 + code + %22, change in %22 + diff + %22 seconds%22);%0A%09%09%09Thread.sleep(1000);%0A%09%09%7D%0A%09%7D%0A%7D%0A

Create TwoFactorAuthUtilTest.java