Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
deb13:otp_authenticator_for_php [2026/08/30 23:24] Bernard Condraudeb13:otp_authenticator_for_php [2026/08/30 23:47] (current) Bernard Condrau
Line 9: Line 9:
 source /home/user/html/pyotp-env/bin/activate</code> source /home/user/html/pyotp-env/bin/activate</code>
   - Install pyotp:<code>pip3 install pyotp</code>   - Install pyotp:<code>pip3 install pyotp</code>
-  - Check execution of pyotp:<code></code> +  - Create the python script ''/home/user/html/pyotp-env/otp.py'':<code># Python script to generate authenticator OTP 
-  - Create the python script:<code># Python script to generate authenticator OTP +import pyotp
-import pyotp:<code>/home/bco/html/otp.py</code>+
  
 # 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 21: Line 20:
 # Generate the current 6-digit code # Generate the current 6-digit code
 current_code = totp.now() current_code = totp.now()
-print(f"Current 6-digit code: {current_code}")</code> +print(current_code)</code> 
-  - Create the +  Check execution of pyotp:<code>python3 /home/user/html/pyotp-env/otp.py</code> 
 +  - Create a bash script:<code>vim /home/user/html/otp.sh 
 +#!/bin/bash 
 +source /home/user/html/pyotp-env/bin/activate 
 +python3 /home/user/html/pyotp-env/otp.py 
 +deactivate 
 +exit 0</code> 
 +  - Create a php web page which calls the script:<code>vim /home/user/html/otptest.php 
 +<?php 
 +$output = shell_exec('/home/bco/html/otp.sh'); 
 +echo $output;</code> 
 +  - Give the scripts correct ownership and permissions:<code>sudo chown www-data:www-data /home/bco/html/pyotp-env/otp.py 
 +sudo chown www-data:www-data /home/bco/html/otp.sh 
 +sudo chmod +x /home/bco/html/otp.sh</code> 
 +  - In Synology, you can check the OTP like this:<code>synootp username=user code=otp-code</code>