- 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 length 6:
OTP of 6 length: 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)
- Node | URL.password API
- How to store a password in database?
- Password Verification in Node
- jQuery | :password Selector
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.