This is an old revision of the document!


OTP authenticator for php

  1. Create a python virtual environment in a location your web server can access:
    cd /home/user/html
    mkdir -p /home/user/html/pyotp-env
    sudo chown user:www-data /home/user/html/pyotp-env
    sudo chmod 770 /home/user/html/pyotp-env
  2. Create a virtual environment as apache2 user and activate it:
    sudo -s -u www-data
    python3 -m venv /home/user/html/pyotp-env
    source /home/user/html/pyotp-env/bin/activate
  3. Install pyotp:
    pip3 install pyotp
  4. Check execution of pyotp:
      - Create the python script:<code># Install via terminal: pip install pyotp
    import pyotp:<code>/home/bco/html/otp.py

# Your Base32 secret key (provided when setting up 2FA) secret = “JBSWY3DPEHPK3PXP”

# Initialize TOTP totp = pyotp.TOTP(secret)

# Generate the current 6-digit code current_code = totp.now() print(f“Current 6-digit code: {current_code}”)</code>