Under OTP, I showed with example how to generate an hotp.
By default the length of the hotp generated will be 6.
We can change that to any number between 6 and 8.
In this post under OTP, I will show with example how to change hotp length to 8.
Below is the complete main code for your reference.
Main Class
1 package defaultPackage;
2
3 import com.bastiaanjansen.otp.HOTP;
4 import com.bastiaanjansen.otp.SecretGenerator;
5
6 public class Example4 {
7 public static void main(String[] args) {
8 byte[] secret = SecretGenerator.generate();
9 HOTP.Builder builder = new HOTP.Builder(secret);
10 builder.withPasswordLength(8);
11 HOTP hotp = builder.build();
12 String otp = hotp.generate(1L);
13 System.out.println(otp);
14 }
15 }
In the above code, at line 9 we are creating an instance of “HOTP.Builder” class named “builder”.
At line 10, we are calling “withPasswordLength” method on the builder instance and passing 8 as an argument.
In this way we are changing the default otp length from 6 to 8 digits.