+ 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

24th Oct 2019, 10:36 AM
Oduola Rasheed Olaide
Oduola Rasheed Olaide - avatar
10 Antworten
+ 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.
24th Oct 2019, 10:41 AM
A͢J
A͢J - avatar
+ 5
Learn Basic Java[Follow If Not Boring] 💻 variable name should be camel Case in java. So here Number should be number.
24th Oct 2019, 8:26 PM
A͢J
A͢J - avatar
+ 2
zemiak Because there is no number 9 in defined String.
24th Oct 2019, 8:25 PM
A͢J
A͢J - avatar
+ 2
25th Oct 2019, 2:37 PM
A͢J
A͢J - avatar
+ 1
USE THIS CODE FRAGMENT: int otp=(int)(Math.random()*899999)+100000;
25th Oct 2019, 4:45 PM
Anmol Pal
Anmol Pal - avatar
0
Thanks 🤝 man 👨
24th Oct 2019, 10:45 AM
Oduola Rasheed Olaide
Oduola Rasheed Olaide - avatar
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.
24th Oct 2019, 8:17 PM
zemiak
0
Thanks 🤝 man 👨
24th Oct 2019, 8:41 PM
Oduola Rasheed Olaide
Oduola Rasheed Olaide - avatar
- 1
wow
25th Oct 2019, 2:23 PM
MD Torikot Rahman
MD Torikot Rahman - avatar
- 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
7th Mar 2021, 5:07 PM
Bastiaan Jansen
Bastiaan Jansen - avatar