Skip to content
/ py2fa Public

Desktop Python 2FA Authenticator Tkinter GUI app and script. The script generates two factor authentication codes for secret keys from json file.

Notifications You must be signed in to change notification settings

atomjoy/py2fa

Repository files navigation

Py2FA Google Authenticator in Python

Google Authenticator desktop GUI and script application in Python with JSON secrets.

How to

Install python3 and modules

# Check
which python3

# Install
sudo apt install python3 python3-pyotp python3-tk -y

Add secrets

First add your 2FA secrets to the secrets.json file (when enabling github two factor auth get secret key).

{
  "atomjoy_github": "JBSWY3DPEHPK3PXP",
  "moovspace_github": "JBSWY3DPEHPK3PXD"
}

Run script

The script generates 2fa codes for secrets.

# Gui desktop app tkinter
python3 main.py

# Console script
python3 auth.py

# Console script (30 seconds loop)
python3 2fa.py

Output

Label atomjoy_github Secret JBSWY3DPEHPK3PXP Code 280070
Label moovspace_github Secret JBSWY3DPEHPK3PXD Code 304997

Random secret base32

#!/usr/bin/python3

import pyotp
import time

# Base32 secret
secret = pyotp.random_base32()

# Code from secret
x = pyotp.TOTP(secret)
code = x.now()

# Show
print(secret)
print(code)

# Code verified for current time
print(x.verify(code)) # True

# time.sleep(35)
# print(x.verify(code))

Edit and copy PyF2A activator

For Linux Debian 12 Gnome 43+

# Edit this line change main.py file location
Exec=/bin/python3 /home/username/Dokumenty/github/py2fa-gui/main.py %u

# And copy app activator file to
cp py2fa.desktop /home/username/.local/share/applications

Links