From fe250668fc8f126fe9fab4782aff8eca1b852e46 Mon Sep 17 00:00:00 2001 From: Dita Aji Pratama Date: Sun, 6 Jul 2025 23:36:05 +0700 Subject: [PATCH] First commit --- authenticator.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 authenticator.py diff --git a/authenticator.py b/authenticator.py new file mode 100644 index 0000000..93de8f1 --- /dev/null +++ b/authenticator.py @@ -0,0 +1,39 @@ +import pyotp +import time +import os + +def clear_screen(): + os.system("cls" if os.name == "nt" else "clear") + +def show_otp(issuer, account, secret): + totp = pyotp.TOTP(secret) + try: + while True: + clear_screen() + current_otp = totp.now() + time_remaining = totp.interval - (int(time.time()) % totp.interval) + print("TOTP Authenticator\n") + print(f"{issuer}\n{account}\n") + print(current_otp) + print(f"\nRemaining: {time_remaining:2} sec") + for i in range(time_remaining, 0, -1): + print(f"\rRefresh in: {i:2} sec", end="") + time.sleep(1) + if i == 1: + break + except KeyboardInterrupt: + pass + print("\nEND") + +def app(): + issuer = None + account = None + secret = None + try: + show_otp(issuer, account, secret) + except KeyboardInterrupt: + pass + +if __name__ == "__main__": + app() +