- 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
- One Time Password (OTP) algorithm in Cryptography
- Python Program to create an OTP by squaring and concatenating the odd digits of a number
- How to Sign In with raw password when password store in the database are hashed form in Node.js ?
- How to compare password and confirm password inputs using express-validator ?
- Securing Django Admin login with OTP (2 Factor Authentication)
- How to store a password in database?
- MySQL | Change User Password
- Node JS | Password Hashing with Crypto module
- HTML | DOM Input Password Object
- jQuery | :password Selector
- HTML | DOM Input Password type Property
- HTML | DOM Input Password value Property
- HTML | DOM Input Password defaultValue Property
- HTML | DOM Input Password autofocus Property
- HTML | DOM Input Password disabled Property
- HTML | DOM Input Password pattern Property
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.