How to generate OTP Number with 6 digits

后端 未结 9 1999
小蘑菇
小蘑菇 2020-12-30 17:24

What is an OTP number in a login authentication system? Is there any specific algorithm for generating OTP numbers using java (android). Or is an OTP something like random n

9条回答
  •  醉酒成梦
    2020-12-30 18:11

    Easiest way is to just use DecimalFormat with Random class.

    String otp= new DecimalFormat("000000").format(new Random().nextInt(999999));
    System.out.println(otp);
    

    Sample Outputs,

    002428
    445307
    409185
    989828
    794486
    213934
    

提交回复
热议问题