Now these days, OTP (one time password) is mandatory in almost each and every service. A developer can generate OTP in many ways but the challenge is not to be predictive as any one can predict the OTP and can exploit the service.
Some of popular format of OTPs are:
- 4 or 6 digit Numeric OTP.
- 4 or 6 alphabetic (lowercase / uppercase) OTP.
- 4 or 6 digit alphanumeric OTP.
Examples for n-digit numeric OTP:
Input : n = 4 Output : 8723 Input : n = 8 Output : 23914072
Note: The output of program will be different in every execution.
One of the best way to generate OTP is to use random function. But using random function directly can be dangerous. So here is an method which uses random function and some algorithm for generating the n-digit numeric OTP.
- Find the number of distinct islands in a 2D matrix
- Split a comma delimited string into an array in PHP
- PHP | Imagick edgeImage() Function
- Program for SSTF disk scheduling algorithm
- Program to Insert new item in array on any position in PHP
- PHP program to change date format
- PHP | Sum of digits of a number
- Program to generate CAPTCHA and verify user
- Samsung Semiconductor Institute of Research(SSIR Software) intern/FTE | Set-3
- Count all possible position that can be reached by Modified Knight
- Numbers less than N which are product of exactly two distinct prime numbers
- Length of largest sub-array having primes strictly greater than non-primes
- Minimum odd cost path in a matrix
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.