This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| deb13:otp_authenticator_for_php [2026/08/30 21:24] – Bernard Condrau | deb13:otp_authenticator_for_php [2026/08/30 23:47] (current) – Bernard Condrau | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== OTP authenticator for php ====== | ====== OTP authenticator for php ====== | ||
| - | - Create a python virtual environment in a location your web server can access:< | + | - Create a python virtual environment in a location your web server can access:< |
| - | sudo chown user: | + | mkdir -p /home/user/html/ |
| - | sudo chmod 770 /home/user/www/pyotp-env | + | sudo chown user: |
| + | sudo chmod 770 /home/user/html/pyotp-env | ||
| </ | </ | ||
| - | + | - Create a virtual environment as apache2 user and activate it:< | |
| - | - Create the python script:< | + | python3 -m venv / |
| + | source / | ||
| + | - Install pyotp:< | ||
| + | - Create the python script | ||
| import pyotp | import pyotp | ||
| # Your Base32 secret key (provided when setting up 2FA) | # Your Base32 secret key (provided when setting up 2FA) | ||
| - | secret = "JBSWY3DPEHPK3PXP" | + | secret = "ABCDE1FGHIJK2LMN" |
| # Initialize TOTP | # Initialize TOTP | ||
| Line 16: | Line 20: | ||
| # Generate the current 6-digit code | # Generate the current 6-digit code | ||
| current_code = totp.now() | current_code = totp.now() | ||
| - | print(f" | + | print(current_code)</ |
| + | | ||
| + | - Create a bash script:< | ||
| + | # | ||
| + | source / | ||
| + | python3 / | ||
| + | deactivate | ||
| + | exit 0</ | ||
| + | - Create a php web page which calls the script:< | ||
| + | <?php | ||
| + | $output = shell_exec('/ | ||
| + | echo $output;</ | ||
| + | - Give the scripts correct ownership and permissions:< | ||
| + | sudo chown www-data: | ||
| + | sudo chmod +x / | ||
| + | - In Synology, you can check the OTP like this:< | ||