A one-time password (OTP) is a temporary, unique code generated for a single login session or transaction. Unlike static passwords, OTPs expire after a short period (usually 30-60 seconds) or upon use, adding an extra layer of security. They are commonly delivered via SMS, email, or authenticator apps.
OTPs work by using a shared secret between the user and the service. Time-based OTPs (TOTP) generate codes based on the current time and a secret key. Event-based OTPs (HOTP) increment a counter each time a code is requested. Both methods use cryptographic hash functions to produce a numeric code that is hard to predict.
When a user requests an OTP, the server generates a code and sends it to the registered contact method. The user then enters the code, and the server verifies it by comparing it to a locally computed value. If they match, access is granted. Because each code is valid only once, even if intercepted, it cannot be reused.