Last updated
Last updated
This page contains recommendations for using One-Time Passwords (OTPs).
Use an OTP once. Delete an OTP or transfer it to a final status that prohibits reusing.
Link an OTP to an individual user in a database.
Use OTPs of length 6+ symbols.
Set a short expiration time for an OTP (~ 5 hours).
Make sure the generation of new OTP invalidates previous ones.
Store OTPs in a separate database, access to which must be limited. Do not store OTPs next to other application data.
Do not send OTPs in an URL (in the path, query, or fragment).
Store OTPs in encrypted form and decrypt only certain records when accessed.
Set a short expiration time for an OTP (~ 1 minute).
Include information about the confirmed action in the text templates of messages with OTPs. For example, if a user uses OTP to cancel a subscription, the message can be like this:
TOTP is an algorithm that generates OTPs based on a shared secret and the current time. To generate OTPs, a user needs an authenticator application (also known as a prover
). In other words, a user and a backend generate an OTP separately, but thanks to the shared secret and the current time, a backend can reproduce the same OTP in a certain period.
Use a unique shared secret for each authenticator application (prover). For example, if TOTP is used to generate OTPs for a second-factor authentication, generate a unique shared secret for each TOTP registration.
Use shared secrets of length 16+ bytes.
Set a short expiration time for an OTP (~ 1 minute).
The OTP generation step and OTP expiration time must be equal (~ 1 minute). In other words, the generation of a new OTP must invalidate previous ones.
If you need to generate OTP on the server side and send it to a user via one of the communication channels (email, SMS, push, etc.), use a cryptographically strong random generator, see the page.
If you need to generate OTP on the client side, use time-based one-time passwords (TOTPs), see the section.
If an application generates OTPs on the server side, limit the number of generation attempts in a certain period, see the page.
Limit the number of OTP verification attempts for a certain period, see the page.
Comply with requirements from the page.
Comply with requirements from the page.
Comply with requirements from the page.
Time-Based One-Time Password Algorithm (TOTP) is described in .
Generate a shared secret using a cryptographically strong random generator, see the page.