/** * * @param token * @param key * @param counter * @return -1 if not a match. A positive number means successful validation. This positive number is also the new value of the counter */ public int validateHOTP(String token, String key, int counter) { int newCounter = counter; for (newCounter = counter; newCounter <= counter + lookAheadWindow; newCounter++) { String candidate = generateHOTP(key, newCounter); if (candidate.equals(token)) { return newCounter + 1; } } return -1; }
/** * * @param token * @param key * @param counter * @return -1 if not a match. A positive number means successful validation. This positive number is also the new value of the counter */ public int validateHOTP(String token, String key, int counter) { int newCounter = counter; for (newCounter = counter; newCounter <= counter + lookAheadWindow; newCounter++) { String candidate = generateHOTP(key, newCounter); if (candidate.equals(token)) { return newCounter + 1; } } return -1; }