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.
- Generating Random String Using PHP
- Strong Password Suggester Program
- Maximum removal from array when removal time >= waiting time
- PHP | Date and Time
- PHP | time() Function
- Queries of nCr%p in O(1) time complexity
- Polynomial Time Approximation Scheme
- Measuring script execution time in PHP
- Convert timestamp to readable date/time in PHP
- PHP | Spreadsheet | Setting a date and/or time value in a cell
- Extended Mo's Algorithm with ≈ O(1) time complexity
- Find maximum in a stack in O(1) time and O(1) extra space
- Count Fibonacci numbers in given range in O(Log n) time and O(1) space
- Operating System | Priority Scheduling with different arrival time - Set 2
- K'th Smallest/Largest Element in Unsorted Array | Set 2 (Expected Linear Time)
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.