+ 4
How to generate One Time Password(OTP) in Java.?
You can check my code here if it need any corrections, but the code run without Error.. đ đ https://code.sololearn.com/clmM38bj95TM/?ref=app
10 Respostas
+ 5
Your code is ok and well working. No need to ask how to generate. It's right code to generate OTP. But one suggestion generate OTP more than 4 character till 6 to 8 is ok.
+ 5
Learn Basic Java[Follow If Not Boring] đ» variable name should be camel Case in java. So here Number should be number.
+ 2
zemiak Because there is no number 9 in defined String.
+ 2
MD Torikot Rahman What wow?
+ 1
USE THIS CODE FRAGMENT:
int otp=(int)(Math.random()*899999)+100000;
0
Thanks đ€ man đš
0
it is not a good practice to use the Number as a variable name because it is a standard class name.
Now your code ignores number 9 in the result.
The pseudo-random number is not really safe, but may be sufficient for this purpose.
Maybe it would be more convenient to get a String as a result,
and without output console message inside method.
0
Thanks đ€ man đš
- 1
wow
- 1
These are not actually one-time passwords (OTP) and can therefore not be used with, for example, Google Authenticator or similar apps. OTP's are defined in RFC 4226 (HOTP) and RFC 6238 (TOTP). I created a library, so if you want to take a look at the code: https://github.com/BastiaanJansen/OTP-Java