- Math.random(): This function returns any random number between 0 to 1.
- Math.floor(): It returns floor of any floating number to a integer value.
Using the above function pick random index of string array which contains all the possible candidates of a particular digit of the OTP.
Example 1: This example generates 4 digit Numeric OTP:
OTP of 4 digits: 2229
Example 2: This example generates 6 digit Numeric OTP:
OTP of 6 digits: 216664
Example 3: This example generates alphanumeric OTP of lenght 6:
OTP of 6 lenght: rab0Tj
- Program to generate random alphabets
- Program to generate random string in PHP
- PHP program to Generate the random number in the given range (min, max)
- How to store a password in database?
- jQuery | :password Selector
- HTML | DOM Anchor password Property
- HTML | DOM Input Password name Property
- MySQL | Change User Password
- HTML | DOM Input Password Object
- Cryptography | One Time Password (OTP) algorithm
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.