Notice

╠ This is my personal blog and my posts here have nothing to do with my employers or any other association I may have. It is my personal blog for my personal experience, ideas and notes. ╣

Monday, April 27, 2020

One Time Password Generator

Simple code to generate One Time Password.
We are using java.util.SplittableRandom which was introduced in Java 8.
import java.util.SplittableRandom;
public class OTPgenerator {
public static void main(String[] p) {
int len = 6;
if(p.length > 0) {
len = Integer.valueOf(p[0]);
}
StringBuilder sb = new StringBuilder();
SplittableRandom ran = new SplittableRandom();
for(int i =0; i < len; i++) {
int n = ran.nextInt(1,10);
sb.append(n);
}
System.out.println(" Gnerated OTP " + sb.toString());
}
}

Output