TL;DR
This guide shows you how to let users access your system without needing them to create an account first. We’ll use temporary, one-time codes sent by email or generated on demand.
1. Understand the Risks and Benefits
Benefits:
- Faster access for users who only need occasional entry.
- Reduced friction – no signup forms to complete.
Risks:
- Lower security than full registration (no password reset, account recovery).
- Potential for abuse if codes are easily guessable or shared.
This method is best suited for low-sensitivity applications.
2. Choose an Authentication Method
We’ll cover two main approaches:
- Email Verification: A unique code is emailed to the user upon request.
- Time-Based One-Time Passwords (TOTP): Codes are generated on demand, often using a QR code or manual input.
3. Email Verification Implementation
- Generate a Unique Code: When a user requests access, create a random alphanumeric code (e.g., 6-8 characters). Ensure it’s unlikely to collide with existing codes.
- Store the Code and User Email: Temporarily store the code associated with the user’s email address in your database. Include an expiry timestamp (e.g., 15 minutes).
- Send the Email: Send an email containing the unique code to the provided email address.
- Verification Process: When the user enters the code, check if it matches the stored code for that email and hasn’t expired. If valid, grant access.
- Code Expiry: Regularly clean up expired codes from your database (e.g., using a scheduled task).
Example Python code snippet to generate a random code:
import secrets
import string
def generate_code(length=8):
alphabet = string.ascii_letters + string.digits
return ''.join(secrets.choice(alphabet) for i in range(length))
4. TOTP Implementation
- Install a TOTP Library: Use a library like
pyotp(Python), or similar libraries in other languages. - Generate a Secret Key: For each user requesting access, generate a unique secret key. Store this securely.
- Display the QR Code/Manual Input: Present the user with a QR code containing the secret key and your application’s name (for use in authenticator apps like Google Authenticator or Authy). Alternatively, provide the secret key as text for manual input.
- Verification Process: When the user enters the TOTP code from their app, verify it against the stored secret key using the library function.
Example Python code snippet to generate a QR code:
import pyotp
import qrcode
def generate_totp_qr(secret_key, application_name):
totp = pyotp.TOTP(secret_key)
uri = totp.provisioning_uri(application_name=application_name)
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(uri)
qr.make(fit=True)
return qr
5. Security Considerations
- Code Length: Use sufficiently long codes (6-8 characters minimum for email verification).
- Expiry Times: Keep code expiry times short (e.g., 15 minutes) to limit the window of opportunity for abuse.
- Rate Limiting: Limit the number of code requests from a single IP address or email address to prevent brute-force attacks.
- Secure Storage: Protect secret keys used in TOTP implementations.
- HTTPS: Always use HTTPS to encrypt communication and protect sensitive data like codes.

