This project is a application that generates and retrieves one-time passwords (OTPs) using the TOTP (Time-based One-Time Password) algorithm. It includes functionality to generate a QR code for setting up the OTP in an authenticator app and to continuously display the current OTP.
The implementation consists of the following components:
main.py
: The main script that contains two main functionalities:generate_qr()
: Generates a QR code for the OTP and saves it asotp_qr.jpg
. The corresponding secret is saved insecret.txt
.get_otp()
: Continuously displays the current OTP in 30-second intervals.
Makefile
: Automates the build and run processes for the application.
- Python3
pyotp
libraryqrcode
library
You can install the required libraries using:
pip3 install pyotp qrcode
-
The Makefile includes targets to simplify running the commands. In your terminal, type:
make
-
To generate a QR code for setting up the OTP in an authenticator app, run:
./submission --generate-qr
-
To display the current OTP, run:
./submission --get-otp
If you see the "error: externally-managed-environment" error, highly recommend to use a virtual environment.
-
Create a virtual environment using the following command:
python3 -m venv venv
-
Activate the virtual environment:
source venv/bin/activate (on macOS) venv\Scripts\activate (on Windows)
-
Install the required libraries:
pip install pyotp qrcode
-
Follow the steps in the Usage section.
-
If you want to deactivate the virtual environment, run:
deactivate